This seems trivial but I can’t get it to work. Here’s my code:
$args = array(
'numberposts' => -1,
'eventcategory' => 'nice-events',
'post_type' => 'event',
'post_status' => 'publish'
);
var_dump(get_posts($args));
As you can see, my taxonomy is eventcategory
and the term is nice-events
. There are actually over 50 terms and regardless of what term I use in place of nice-events
I always get the same result: all of the posts. So the term is being ignored and I have no idea why.
You cannot make up your own arguments – rather than replacing the
'category'
argument with your taxonomy name, use'tax_query'
.See “taxonomy parameters” section of the codex on get_posts.
Alternatively, you could make use of the
WP_Query
class: