Last active
February 17, 2020 03:40
-
-
Save wplit/f30aee1074e8628d210de0058e829c44 to your computer and use it in GitHub Desktop.
Exclude posts with specific taxonomy term
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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