wordpress 后台添加自定义分类筛选?

本文介绍如何在WordPress中为自定义帖子类型添加分类过滤功能。通过使用PHP代码,可以实现在管理后台的帖子列表页面上添加下拉菜单来筛选特定分类的帖子。这种方法不仅提升了用户体验,还方便了网站管理员的管理工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考网址:http://wordpress.stackexchange.com/questions/578/adding-a-taxonomy-filter-to-admin-list-for-a-custom-post-type

/* overwrite drop down select by category
-----------------------------------------*/
add_action('restrict_manage_posts','overwrite_listings_by_category');
function overwrite_listings_by_category() {
    global $typenow;
    global $wp_query;

    if ($typenow=='post') {
        $taxonomy = 'category';
        $category_taxonomy = get_taxonomy($taxonomy);
		//return print_r($wp_query->query);
        return wp_dropdown_categories(array(
            'show_option_all' =>  __("Show All {$category_taxonomy->label}"),
            'taxonomy'        =>  $taxonomy,
            'name'            =>  'cat',
            'orderby'         =>  'name',
            'selected'        =>  @$wp_query->query['cat'],
            'hierarchical'    =>  true,
            'depth'           =>  5,
            'show_count'      =>  true, // Show # listings in parens
            'hide_empty'      =>  true, // Don't show businesses w/o listings
        ));
    }
}

The Screenshots:

...let's check out some screen shots for the finished product:

Listings list page with No Filtering:

Listings list page with No Filtering

Listings list page With Filtering:

Listings list page With Filtering



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值