Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WP_Query tax_查询多个分类法和术语_Php_Wordpress_Post_Custom Post Type_Taxonomy - Fatal编程技术网

Php WP_Query 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 =

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

我使用一个选择菜单用页面的分类信息(在本例中是产品页面)填充选择选项。在tax_查询中使用单个分类法和术语都很好,但只要我尝试使用数组传递倍数,我就不再返回任何内容。这似乎很简单,但我遗漏了一些东西。有什么想法吗

以下是我的工作内容:

$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。一切都好。非常感谢。