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

时间:2017-10-02 19:11:55

标签: wordpress taxonomy-terms

简单查询但由于某些原因未显示正确的帖子,尝试显示带有每月待办事项列表字词的帖子,如果没有结果则会显示社区帖子 - 事件'术语。有什么建议吗?

.translation

1 个答案:

答案 0 :(得分:2)

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

$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'
);

您可能会注意到条款是复数,您也可以像这样简化查询:

$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'
);