2013-08-16 51 views
5

我想顯示具有自定義分類的自定義帖子類型,但我沒有任何運氣。什麼都沒有顯示出來。我感謝任何幫助。自定義分類WP_Query

類型=畫廊

自定義分類蛞蝓= photoarea

的 'photoarea' 我想顯示=第四

enter image description here

<?php 

$args = array( 
       'post_type' => 'gallery', 
       'tax_query' => array(
        array(
         'taxonomy' => 'photoarea', 
         'field' => 'fourth', 
         ) 
       ), 
       'posts_per_page' => 10, 
      ); 

$the_query = new WP_Query($args); 


if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); 

    the_post_thumbnail(); 

endwhile; endif; 

wp_reset_query(); 

?> 

回答

1

如果我的理解是正確的,那您需要使用以下代碼獲取自定義分類: 而不是field您必須使用term獲得職位第四

<?php 

$args = array( 
       'post_type' => 'gallery', 
       'tax_query' => array(
        array(
         'taxonomy' => 'photoarea', 
         'term' => 'fourth', 
         ) 
       ), 
       'posts_per_page' => 10, 
      ); 

$the_query = new WP_Query($args); 


if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); 

    the_post_thumbnail(); 

endwhile; endif; 

wp_reset_query(); 

?> 
+0

不適用於我。它觸發了一個PHP通知。 –

+0

你需要'field'=>'slug'和'terms'=>'fourth'來獲得這項工作,而不是'term'。 –

1

您可以使用下面的代碼片段:

$the_query = new WP_Query('post_type=gallery&photoarea=fourth'); 

,然後while循環。

-2
$args = array('post_type' => 'gallery','posts_per_page'=>'-1','tax_query' => array(array(
             'taxonomy' => 'photoarea', 
             'field' => 'term_id', 
             'terms' => $your_term_id, 
            ), 
           ), 
          ); 
相關問題