I have this code:
query_posts( array(
'post_type' => APP_POST_TYPE,
'post_status' => 'publish',
'posts_per_page' => 4,
),
) );
now I need to remove all post from this Query APP_TAX_STORE => $term->slug
Meaning I need to show all posts except the one from this one taxonomy.
I have this code:
query_posts( array(
'post_type' => APP_POST_TYPE,
'post_status' => 'publish',
'posts_per_page' => 4,
),
) );
now I need to remove all post from this Query APP_TAX_STORE => $term->slug
Meaning I need to show all posts except the one from this one taxonomy.
The easiest way I can see is to gather a list of the terms in that taxonomy, and use them with a NOT IN
operator in your query's tax_query
:
// Get all the terms in your custom taxonomy.
$slugs = get_terms( [
'taxonomy' => 'industry',
'fields' => 'slugs',
] );
$posts = query_posts( [
'post_type' => 'post',
'posts_per_page' => 4,
'post_status' => 'publish',
'tax_query' => [
[
'taxonomy' => APP_TAX_STORE,
'operator' => 'NOT IN',
'field' => 'slug',
'terms' => $slugs,
]
]
] );
I would suggest reading up on query_posts if you haven't already - heed the warning that it could cause confusion and trouble down the road. get_posts
should get you the same results without the burden of overwriting the main query.
Okay found a solution that's working as well:
query_posts( array(
'post_type' => APP_POST_TYPE,
'post_status' => 'publish',
'posts_per_page' => 4,
'tax_query' => array(
array(
'taxonomy' => APP_TAX_STORE,
'field' => 'slug',
'terms' => $term->slug,
'operator' => 'NOT IN',
),
),
) );
category
ortag
, or is a custom taxonomy? – phatskat Commented Feb 2, 2019 at 23:46