<?php $project_query = new WP_Query( 'post_type=product&posts_per_page=-1&paged='.get_query_var('paged')); ?>
I have a taxonomy called "collection" and create categories like "Art". I have one category called Sold Art with an id of 32. I would like to show my custom post types above but exclude terms from "collection"
Yakir Sitbon answers:
http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
<?php
$project_query = new WP_Query( array(
'post_type' => 'product',
'posts_per_page' => -1,
'paged' => get_query_var( 'paged' ),
'tax_query' => array(
array(
'taxonomy' => 'collection',
'field' => 'id',
'terms' => array( '32' ),
'operator' => 'NOT IN',
),
),
) );
?>
Yakir Sitbon comments:
Rick, Please see my code..
Rick Bible comments:
this works great, you got my money
Charles Klycinski answers:
Hi here is example how to exclude taxomony slugs:
$args = array(
'post_type' => array( 'product' ),
'tax_query' => array(
array(
'taxonomy' => 'collection',
'field' => 'slug',
'terms' => '<PUT YOUR TERMS HERE>',
'operator' => 'NOT IN'
)
)
);
$myquery = new WP_Query( $args );
while( $myquery->have_posts() ):
$myquery->the_post();
# do your stuff here
endwhile;
Rick Bible comments:
I've seen this, viewed it myself before coming here to "ask a question". I don't know how to code the above into my query
Giri answers:
Replace your "sold art" term slug with the one i used. I used sold-art
?php
$args = array(
'post_type' => 'products',
'posts_per_page' => -1,
'post_status' => 'publish',
'paged' => get_query_var('paged'),
'tax_query'=> array( 'taxonomy' => 'collection',
'term' => 'sold-art',
'operator' => 'NOT IN'
)
)
);
$products = new WP_Query($args); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php endwhile; ?>