2014-09-01 113 views
0

自定義帖子類型的分類查詢不顯示結果。定期查詢自定義類型顯示結果。我可以將自定義稅賦分配給自定義類型。當我運行查詢時,我什麼也得不到,只是一個錯誤。我得到這個錯誤:wordpress - WP查詢自定義類型/稅不顯示帖子

Notice: Undefined offset: 0 in /Applications/MAMP/htdocs/folsom/wp-includes/query.php on line 2526 

這裏是我的查詢:

 $args = array(
      'post_type' => 'product', 
      'tax_query' => array(
       array(
        'taxonomy' => 'product-cat', 
        'term' => 'featured', 
        'field' => 'slug' 
        ) 
      ) 
     ); 

**更新:命中進入我做了。我在添加更多信息的過程中

**更新:我確保將分類法添加到參數類型的參數中,定義了優先級,以便他們首先註冊。

add_action('init', 'create_product_taxonomies', 0); 

add_action('init', 'setup_custom_post'); 
function setup_custom_post(){ 
$args = array(
    'label'     => 'products', 
    // Bunch of other stuff 
    'taxonomies'   => array('product-cat'), 
    ), 

); 

register_post_type('product', $args); 
} 
+1

你要添加其他內容? – 2014-09-01 02:40:59

回答

1

看起來像添加了錯誤的分類參數。使用'條款'而不是'條款'。所以,你的參數數組看起來象下面這樣:

$args = array(
     'post_type' => 'product', 
     'tax_query' => array(
      array(
       'taxonomy' => 'product-cat', 
       'terms' => 'featured', 
       'field' => 'slug' 
       ) 
     ) 
    ); 

欲瞭解更多信息請訪問http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

+0

錯別字。總是一個錯字...:/ – Plummer 2014-09-01 12:44:28

相關問題