2015-04-07 90 views
0

我試圖運行從單個類別返回我的自定義帖子的查詢。我嘗試了類別ID('cat'=> 83)和類別子彈('category_name => 'slugname'),但都返回空結果。WP_Query - 在特定類別中顯示自定義帖子

$custom_args = array(

'post_type' => 'event', 
'cat' => 83, 
'posts_per_page' => 10, 
'paged' => $paged, 
'meta_key' => 'event_date', // name of custom field 
'orderby' => 'meta_value_num', 
'order' => 'ASC' 
); 

$custom_query = new WP_Query($custom_args); 
+0

是您的自定義帖子類型註冊使用內置類別還是它使用的自定義分類標準? –

+0

嗨。這是我認爲的一種定製分類法。 –

回答

0

如果您使用自定義分類,那麼你需要修改您的查詢像如下:

$custom_args = array(

'post_type' => 'event', 
'tax_query' => array(
     array(
      'taxonomy' => 'custom taxonomy', 
      'field' => 'slug', //can be set to ID 
      'terms' => 'bob' //if field is ID you can reference by cat/term number 
     ) 
    ) 
'posts_per_page' => 10, 
'paged' => $paged, 
'meta_key' => 'event_date', // name of custom field 
'orderby' => 'meta_value_num', 
'order' => 'ASC' 
); 

$custom_query = new WP_Query($custom_args); 

希望它可以幫助你。

+0

嗨,我試着把這段代碼放進去,並打破了頁面(死亡的白頁)。/ –

+0

您是否已經定義了您的**自定義分類法的名稱** here =>''tax_query'=> array( array( 'taxonomy'=>'custom taxonomy', 'field'=>'slug',//可以設置爲ID 'terms'=>'bob'// if field is ID you can reference by cat/term number ) –

+0

Yes,I lifting the整個數組,並把它代替我的查詢。感謝迄今爲止的幫助,順便說一句! –

相關問題