WP_Querytax_query多个分类法和术语

TRe*_*Rex 2 php wordpress post taxonomy custom-post-type

我在返回具有多个分类法和术语的帖子时遇到了一些麻烦。希望比我更有知识的人可以帮助我理解。

我使用选择菜单来使用页面(在本例中为“产品”页面)的分类信息填充选择选项。在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
     )
  )
)
Run Code Online (Sandbox Code Playgroud)

Gui*_*ral 5

你的错误是一个键数组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
     )
  )
Run Code Online (Sandbox Code Playgroud)

参考wordpress