介质的自定义分类筛选器

时间:2016-09-26 作者:JCJ

我的媒体库的管理员中已经有以下代码:

function atelier_add_iCat_taxonomy() {
    $labels = array(
        \'name\'              => \'iCats\',
        \'singular_name\'     => \'iCat\',
        \'search_items\'      => \'Search iCats\',
        \'all_items\'         => \'All iCats\',
        \'parent_item\'       => \'Parent iCat\',
        \'parent_item_colon\' => \'Parent iCat:\',
        \'edit_item\'         => \'Edit iCat\',
        \'update_item\'       => \'Update iCat\',
        \'add_new_item\'      => \'Add New iCat\',
        \'new_item_name\'     => \'New iCat Name\',
        \'menu_name\'         => \'iCat\',
    );

    $args = array(
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'query_var\' => \'true\',
        \'rewrite\' => \'true\',
        \'show_admin_column\' => \'true\',
    );

    register_taxonomy( \'iCat\', \'attachment\', $args );
}
add_action( \'init\', \'atelier_add_iCat_taxonomy\' );
我想一个过滤器,以确保属于某一类别的图像只显示。

尝试了以下方法,但它显示了主要类别,而不是我的自定义分类法。

function atelier_add_image_category_filter() {
    $screen = get_current_screen();
    if ( \'upload\' == $screen->id ) {
        $dropdown_options = array( \'show_option_all\' => __( \'View all categories\', \'iCats\' ), \'hide_empty\' => false, \'hierarchical\' => true, \'orderby\' => \'name\', );
        wp_dropdown_categories( $dropdown_options );
    }
}
add_action( \'restrict_manage_posts\', \'atelier_add_image_category_filter\' );
我是否遗漏了什么,或者是否有其他解决方案?

1 个回复
SO网友:Jim-miraidev

可以添加分类参数。

function add_image_category_filter() {
    $screen = get_current_screen();
    if ( \'upload\' == $screen->id ) {
        $dropdown_options = array( 
            \'taxonomy\' => \'YOUR_TAXONOMY\', 
            \'show_option_all\' => __( \'View all categories\', \'iCats\' ), 
            \'hide_empty\' => true, 
            \'hierarchical\' => true,
             // default is cat which wouldn\'t filter custom taxonomies
            \'value_field\'       => \'slug\',
            \'name\'              => \'YOUR_TAXONOMY\', 
            \'orderby\' => \'name\', );
        wp_dropdown_categories( $dropdown_options );
    }
}
add_action( \'restrict_manage_posts\', \'add_image_category_filter\' );

相关推荐