Skip to content

Instantly share code, notes, and snippets.

@wplit
Last active February 17, 2020 03:40
Show Gist options
  • Select an option

  • Save wplit/f30aee1074e8628d210de0058e829c44 to your computer and use it in GitHub Desktop.

Select an option

Save wplit/f30aee1074e8628d210de0058e829c44 to your computer and use it in GitHub Desktop.
Exclude posts with specific taxonomy term
<?php // first code block
add_action( 'pre_get_posts', 'lit_taxonomy_term_filter' );
function lit_taxonomy_term_filter($query) {
$taxonomy = 'category'; // My Taxonomy
$terms = array('travel', 'food'); // My terms to exclude
$tax_query = array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $terms ,
'operator' => 'NOT IN',
);
$query->tax_query->queries[] = $tax_query;
$query->query_vars['tax_query'] = $query->tax_query->queries;
}
?>
Your repeater / easy posts would be here
<?php // second code block
remove_action( 'pre_get_posts', 'lit_taxonomy_term_filter' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment