首先,在你的图片中,你可以看到WordPress允许你按类别过滤帖子,只需大声说出你在图片中添加了什么,但是如果你想知道如何将自己的链接添加到过滤器中,你可以使用views_edit-post
过滤器挂钩ex:
add_action(\'pre_get_posts\', \'query_add_filter\' );
function query_add_filter( $wp_query ) {
if( is_admin()) {
add_filter(\'views_edit-post\', \'Add_My_filter\');
}
}
// add filter
function Add_My_filter($views) {
global $wp_query;
unset($views[\'mine\']);
$my_cat = YOUR-CAT-ID
$query = array(
\'author\' => $current_user->ID,
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'cat\' => $my_cat
);
$result = new WP_Query($query);
$class = ($wp_query->query_vars[\'cat\'] == \'featured\') ? \' class="current"\' : \'\';
$views[\'publish_f\'] = sprintf(__(\'<a href="%s"\'. $class .\'>Publish Featured <span class="count">(%d)</span></a>\', \'publish featured\'),
admin_url(\'edit.php?post_status=publish&post_type=post&cat=\'.$my_cat),
$result->found_posts);
return $views;
}
你一定要换衣服
YOUR-CAT-ID
到实际类别id