Php WP_Query tax_查询多个分类法和术语
我在返回包含多个分类法和术语的帖子时遇到了一些麻烦。希望比我有更多知识的人能帮助我理解 我使用一个选择菜单用页面的分类信息(在本例中是产品页面)填充选择选项。在tax_查询中使用单个分类法和术语都很好,但只要我尝试使用数组传递倍数,我就不再返回任何内容。这似乎很简单,但我遗漏了一些东西。有什么想法吗 以下是我的工作内容:Php WP_Query tax_查询多个分类法和术语,php,wordpress,post,custom-post-type,taxonomy,Php,Wordpress,Post,Custom Post Type,Taxonomy,我在返回包含多个分类法和术语的帖子时遇到了一些麻烦。希望比我有更多知识的人能帮助我理解 我使用一个选择菜单用页面的分类信息(在本例中是产品页面)填充选择选项。在tax_查询中使用单个分类法和术语都很好,但只要我尝试使用数组传递倍数,我就不再返回任何内容。这似乎很简单,但我遗漏了一些东西。有什么想法吗 以下是我的工作内容: $producttype = $_GET['ProductType']; $businessunit = $_GET['BusinessUnit']; $products =
$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\u 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
)
)
Reference$producttype是数组吗?同样的$businessunit?很好,Guillermo!这就是我用记事本得到的。然而,我已经修复了我的打字错误,它现在正在返回结果,但仍然没有返回正确的结果。数组中的第二项似乎被忽略。否。这是正确的。你说得对。我需要使用AND运算符,而不是OR。一切都好。非常感谢。