2013-08-16 19 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の代わりに というコードでカスタムタクソノミーを取得する必要があります

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

してからwhileループ:あなたはコードスニペットの下に使用することができます第四

<?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

'term'ではなく 'field' => 'slug'と 'terms' => 'fourth'が必要です。 –

1

にポストを得るためにtermを使用する必要があります。

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