Created
August 4, 2015 20:52
-
-
Save groovenectar/28d68b9d8555747b8993 to your computer and use it in GitHub Desktop.
This file contains 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 | |
// Add tag_slug__not_in to valid taxonomy queries | |
add_action('parse_tax_query', function($wp_query) { | |
$q = &$wp_query->query_vars; | |
$tax_query = array(); | |
if (!empty($q['tag_slug__not_in'])) { | |
$q['tag_slug__not_in'] = array_map('sanitize_title_for_query', array_unique((array)$q['tag_slug__not_in'])); | |
$tax_query[] = array( | |
'taxonomy' => 'post_tag', | |
'terms' => $q['tag_slug__not_in'], | |
'field' => 'slug', | |
'operator' => 'NOT IN' | |
); | |
} | |
// Merge with existing $wp_query->tax_query | |
if (!empty($tax_query)) { | |
$tmp_tax_query = new WP_Tax_Query($tax_query); | |
$wp_query->tax_query->queries = array_merge( | |
$wp_query->tax_query->queries, | |
$tmp_tax_query->queries | |
); | |
$wp_query->tax_query->queried_terms = array_merge( | |
$wp_query->tax_query->queried_terms, | |
$tmp_tax_query->queried_terms | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment