Exclude category from Custom Post Type archive page?
-
I create a new post type ‘book‘. And i register new taxonomy for post type ‘book’. The name is ‘cat_book‘
Now I want exclude category id ’30’ and ’31’ from archive-book.php
I add this in function:
function exclude_cat( $query ) { if ( !is_admin() && $query->is_main_query() ) { if ( is_post_type_archive( 'book' ) ) { $query->set( 'category__not_in', array( 30, 31 ) ); return; } } } add_action('pre_get_posts','exclude_cat');
But can’t work. Can someone help me, please! Thanks.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Exclude category from Custom Post Type archive page?’ is closed to new replies.