I have an archive page that lists a custom post type called 'event'. I have event posts with the tag 'regular', (the tag has an id of 53). I'd like to exclude these. I tried using pre_get_posts and then $query->set(('tag__not_in', array('53')) but I don't think tag__not_in will work with custom post types. Is there any way to fix this?
add_action( 'pre_get_posts', 'exclude_regular_tag');
function exclude_regular_tag( $query ){
if ( is_admin() || ! $query->is_main_query() )
return;
if ( is_home() ) {
return;
}
if ( is_post_type_archive( 'event' ) ) {
$args = array('53'); //id of 'regular' tag in custom post type 'event'
$query->set('tag__not_in', $args);
return;
}
}
post_tag
taxonomy?tag__not_in
is post type agnostic, it just creates atax_query
with theNOT IN
operator. you can see it in source here. try having a look at the query in the template,var_dump( $wp_query )
and see if it's applying your tax parameters.