Reputation: 1185
Using Wordpress I am trying to show all posts except posts within one category (named Aktuelt). I am not sure how I should solve this problem. Been looking into excerpt, but not sure if that's the way to do it.
$args = array(
'post_type' => 'any',
'posts_per_page' => '6',
'post_taxonomy' => 'any',
);
Could you please provide a working solution? Or ideas how to solve this problem? Thanks.
Upvotes: 0
Views: 28
Reputation: 9941
Use the cat
paraemeter to exclude posts from a specific category. Just add a minus sign in front of the category ID.
'cat' => -1, // This will exclude category 1
If you just have the name of the category, you can use get_term_by()
to get the ID.
// Outside your arguments
$category = get_term_by( 'name', 'Aktuelt', 'category' );
// Inside your arguments
'cat' => -' . $category->term_id,
You can also use a tax_query
and set the field parameter to name inside the tax_query
, but there is a bug if a term has more than one word or a special character in the name. So you should avoid using term names with a tax_query
Upvotes: 2