Wordpress:tax_query 多个术语使用 OR 运算符

Wordpress: tax_query multiple terms using OR operator

简单的查询,但由于某种原因没有显示正确的 posts,试图显示 post 与 monthly-to-do-list 术语,如果没有结果,则显示带有社区事件术语的 post。有什么建议吗?

$todo_args = array(
   'cat' => $my_category_id,
   'posts_per_page' => 1,
   'tax_query' => array(
        'relation' => 'OR',
            array(
               'taxonomy' => 'postkicker',
                'field'    => 'slug',
                'terms'    => 'monthly-to-do-list',
                ),
            array(
                'taxonomy' => 'postkicker',
                'field'    => 'slug',
                'terms'    => 'community-events',
                ),
            ),
    'orderby' => 'date',
    'order' => 'DESC'
);

尝试添加数组并使其像这样:

$todo_args = array(
   'cat' => $my_category_id,
   'posts_per_page' => 1,
   'tax_query' => array(
        'relation' => 'OR',
            array(
               'taxonomy' => 'postkicker',
                'field'    => 'slug',
                'terms'    => array('monthly-to-do-list'),
                ),
            array(
                'taxonomy' => 'postkicker',
                'field'    => 'slug',
                'terms'    => array('community-events'),
                ),
            ),
    'orderby' => 'date',
    'order' => 'DESC'
);

您可能会注意到 terms 是复数,因此您也可以像这样简化您的查询:

$todo_args = array(
   'cat' => $my_category_id,
   'posts_per_page' => 1,
   'tax_query' => array(
            array(
               'taxonomy' => 'postkicker',
                'field'    => 'slug',
                'terms'    => array('monthly-to-do-list','community-events'),
                ),
            ),
    'orderby' => 'date',
    'order' => 'DESC'
);