下面的代码可以在 WordPress 后台文章列表添加排序选项下拉筛选框,支持多种方式排序。

add_action('restrict_manage_posts', function($post_type){
	global $wp_list_table;
	
	list($columns, $hidden, $sortable_columns, $primary) = $wp_list_table->get_column_info();

	foreach($sortable_columns as $sortable_column => $data){
		if(isset($columns[$sortable_column])){
			$orderby_options[$sortable_column]	= $columns[$sortable_column];
		}
	}

	echo wpjam_get_field_html([
		'title'		=>'',
		'key'		=>'orderby',
		'type'		=>'select',
		'value'		=>$_REQUEST['orderby'] ?? '',
		'options'	=>$orderby_options
	]);

	echo wpjam_get_field_html([
		'title'		=>'',
		'key'		=>'order',
		'type'		=>'select',
		'value'		=>$_REQUEST['order'] ?? 'DESC',
		'options'	=>['desc'=>'降序','asc'=>'升序']
	]);
});
微信 OR QQ 扫描二维码与项目经理沟通
我们在线上24小时期待你的声音
微信二维码 qq二维码
解答:WP主题推荐,WP网站建设,Google SEO,百度SEO,专业服务器环境搭建