WP_Query tax_query多个分类法和术语
问题描述:
我在使用多个分类法和术语返回帖子时遇到了一些麻烦。希望有比我更多知识的人能帮助我理解。WP_Query tax_query多个分类法和术语
我正在使用选择菜单来填充页面的分类信息(在本例中是产品页面)的选择选项。对于tax_query中的单个分类和术语来说,所有这一切都很好,但只要我尝试使用数组来传递多个数字,我就不会再返回任何东西。这似乎很简单,但我错过了一些东西。有任何想法吗?
这里是我的工作:
$producttype = $_GET['ProductType'];
$businessunit = $_GET['BusinessUnit'];
$products = new WP_Query(array(
'post_type' => 'products',
'posts_per_page' => 15,
'orderby' => 'title',
'order' => 'ASC',
'paged' => $paged,
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'producttype',
'field' => 'name',
'term' => $producttype
),
array(
'taxonomy' => 'businessunit',
'field' => 'name',
'term' => $businessunit
)
)
)
答
你的错误是一个关键的阵列tax_query =>term
应该terms
$producttype = $_GET['ProductType'];
$businessunit = $_GET['BusinessUnit'];
$products = new WP_Query(array(
'post_type' => 'products',
'posts_per_page' => 15,
'orderby' => 'title',
'order' => 'ASC',
'paged' => $paged,
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'producttype',
'field' => 'name',
'terms' => $producttype
),
array(
'taxonomy' => 'businessunit',
'field' => 'name',
'terms' => $businessunit
)
)
$ producttype是一个数组?和同样的$ businessunit? –