Showing custom taxonomy column in custom posts type listings

前端 未结 4 1886
深忆病人
深忆病人 2021-02-13 06:44

I have created a custom post type named banners. Thereby I register a new taxonomy called location that specifies on which page the banner is t

4条回答
  •  眼角桃花
    2021-02-13 07:36

    In addition to Jonathan Wold answer, you can add the ability to filter by your custom taxonomy like this:

    add_action('restrict_manage_posts', 'filter_post_type_backend_by_taxonomies', 99, 2);
    
    function filter_post_type_backend_by_taxonomies($post_type, $which) {
        if( 'your_post_type' !== $post_type) {
            return;
        }
        
        $taxonomies = array( 'your_custom_taxonomy' );
        
        foreach( $taxonomies as $taxonomy_slug ) {
            $taxonomy_obj = get_taxonomy( $taxonomy_slug );
            $taxonomy_name = $taxonomy_obj->labels->name;
            
            $terms = get_terms($taxonomy_slug);
            
            echo "';
        }
    }
    

提交回复
热议问题