2014-01-29 170 views
2

下面的代码应该获取在自定义分类中没有特定术语的帖子。目前它仍然得到它们。是缺少的东西。Wordpress获取不在自定义分类术语中的帖子

$args = array(
      'numberposts' => '3', 
      'post__not_in' => $post_not_in, 
      'tax_query' => array(
       'taxonomy' => 'topic', 
       'terms' => 9,  
       'field' => 'id', 
       'operator' => 'NOT IN' 
      ) 
     ); 
     $extras = get_posts($args); 

回答

1

重要提示: tax_query需要

税查询参数数组(它需要一个数组的数组)的阵列 - Wordpress Codex on Taxonomy Parameters

你有没有试过?

$args = array(
    'numberposts' => '3', 
    'post__not_in' => $post_not_in, 
    'tax_query' => array(
     array(
      'taxonomy' => 'topic', 
      'terms' => 9,  
      'field' => 'id', 
      'operator' => 'NOT IN' 
     ) 
    ) 
); 
$extras = get_posts($args); 
+0

那么如何获得没有指定分类的帖子? (即条款=>空?) – knutole

+0

@knutole我不确定,但你应该尝试[这个答案](http://stackoverflow.com/a/13204762/27581) –

相关问题