WP_Query tax_query 多个分类法和术语

WP_Query tax_query multiple taxonomies and terms

我在返回包含多个分类法和术语的帖子时遇到了一些麻烦。希望比我知识渊博的人能帮助我理解。

我正在使用 select 菜单用页面(在本例中为产品页面)的分类信息填充 select 选项。 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
     )
  )

引用wordpress