如何使用`查询->set()`设置`Tax_query`

时间:2018-11-09 作者:Riccardo

虽然这样做有效:

$query->set( \'post__not_in\', array( 30140, 30020, 30008, 29998, 29991, 21458, 20197, 11986, 6614 ) );
这不会:

$tax_query = array(
  \'taxonomy\' => \'filter\',
  \'terms\'    => array(30140, 30020, 30008, 29998, 29991, 21458,20197,11986,6614),
  \'field\'    => \'term_id\',
  \'operator\' => \'NOT IN\');
$query->set( \'tax_query\', $tax_query );

1 个回复
SO网友:Krzysiek Dróżdż

代码的主要问题是tax_query 应该是查询数组,而不是单个查询。

$tax_query = array(
    array(
        \'taxonomy\' => \'filter\',
        \'terms\'    => array(30140, 30020, 30008, 29998, 29991, 21458,20197,11986,6614),
        \'field\'    => \'term_id\',
        \'operator\' => \'NOT IN\'
    )
);
$query->set( \'tax_query\', $tax_query );

结束

相关推荐