本文介绍了WordPress:tax_query使用OR运算符的多个术语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简单查询,但由于某些原因未显示正确的帖子,尝试显示带有每月待办事项列表字词的帖子,如果没有结果,则显示与社区相关的帖子-事件的期限.有什么建议吗?
Simple query but for some reason is not displaying the correct posts, trying to display a post with the monthly-to-do-list term, if no results then display a post with the community-events' term. Any suggestions?
$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'
);
推荐答案
尝试添加数组并使它像这样:
try adding array and make it like this :
$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'
);
您可能会注意到术语是复数形式,并且您还可以像这样简化查询:
As you may notice terms is plural and you may also simplify your query like this :
$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'
);
这篇关于WordPress:tax_query使用OR运算符的多个术语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!