Created
October 1, 2013 14:44
-
-
Save bloqhead/6779606 to your computer and use it in GitHub Desktop.
Example WP query that excludes all terms from a custom taxonomy.
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 | |
/** | |
* Taxonomy Exclusion | |
**/ | |
$tax = 'artists'; | |
$terms = array(); | |
$custom_terms = get_terms( $tax, array( 'fields' => 'names' ) ); | |
if( is_array( $custom_terms ) ) { | |
$terms = $custom_terms; | |
} | |
/** | |
* WP Query | |
**/ | |
$custom_query = new WP_Query( | |
array( | |
'post_type' => 'custom_post_type', | |
'posts_per_page' => -1, // display all posts within the CPT | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
'force_no_custom_order' => TRUE, | |
'post_status' => 'publish', | |
'tax_query' => array( array( | |
'taxonomy' => $tax, | |
'terms' => $terms, | |
'field' => 'slug', | |
'operator' => 'NOT IN' | |
) | |
) | |
) | |
); | |
while ( $custom_query->have_posts() ) : $custom_query->the_post(); $slug = $post->post_name; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment