admin管理员组文章数量:1276794
I need to add Filter by Tags and by categories to custom post type in Gutenberg block. I have created a CPT called "newsfeed" and it is displayed correctly in the page editor as shown in the following image.
but does not have the options Filter by Categories and by Filter by Tags like in the post type "Posts".
What can I do to enable these options?
This is the code I use to create the newsfeeds
function add_tags_categories_taxonomy_x5642() {
$labels = array(
'name' => _x( 'Feed Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Feed Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Feed Tags' ),
'all_items' => __( 'All Feed Tags' ),
'edit_item' => __( 'Edit Feed Tag' ),
'update_item' => __( 'Update Feed Tag' ),
'add_new_item' => __( 'Add New Feed Tag' ),
'new_item_name' => __( 'New Feed Tag' ),
'menu_name' => __( 'Feed Tags' ),
);
$args = array(
'labels' => $labels,
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'query_var' => true,
);
register_taxonomy('feeds_tags', 'newsfeed', $args);
$labels = array(
'name' => _x( 'Feed Symbols', 'taxonomy general name' ),
'singular_name' => _x( 'Feed Symbols', 'taxonomy singular name' ),
'search_items' => __( 'Search Feed Symbols' ),
'all_items' => __( 'All Feed Symbols' ),
'edit_item' => __( 'Edit Feed Symbols' ),
'update_item' => __( 'Update Feed Symbols' ),
'add_new_item' => __( 'Add New Feed Symbols' ),
'new_item_name' => __( 'New Feed Symbols' ),
'menu_name' => __( 'Feed Symbols' ),
);
$args = array(
'labels' => $labels,
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'query_var' => true,
);
register_taxonomy('feeds_symbols', 'newsfeed', $args);
register_taxonomy_for_object_type('category','newsfeed');
}
add_action('init', 'add_tags_categories_taxonomy_x5642');
function add_feed_post_type_x1234($query) {
if ( is_home() && $query->is_main_query() ) {
$query->set('post_type', ['post', 'newsfeed']);
}
return $query;
}
add_action('pre_get_posts', 'add_feed_post_type_x1234');
本文标签: plugin developmentHow add Filter by Tags and by categories to custom post type in Gutenberg block
版权声明:本文标题:plugin development - How add Filter by Tags and by categories to custom post type in Gutenberg block 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741219357a2360666.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论