2017-07-17 13 views
0

カスタム投稿タイプ名を使用してカスタム分類のリストを取得する方法。 「製品」という1つの投稿タイプがあり、カテゴリ(シャツ、Tシャツ、ジーンズなど)のリストがあるとしましょう。投稿タイプ名「商品」を使用してカテゴリリストを作成します。特定の投稿タイプの分類リスト

答えて

0

taxonomy- {post_type} .phpの分類リストで投稿リストを取得できます。このファイルでは、指定されたタクソノミの投稿のデフォルトgtリストがあります。

REF:Custom Post Type taxonomy page still showing all posts

またはカスタムtempleteで、

$custom_terms = get_terms('custom_taxonomy'); 

foreach($custom_terms as $custom_term) { 
    wp_reset_query(); 
    $args = array('post_type' => 'custom_post_type', 
     'tax_query' => array(
      array(
       'taxonomy' => 'custom_taxonomy', 
       'field' => 'slug', 
       'terms' => $custom_term->slug, 
      ), 
     ), 
    ); 

    $loop = new WP_Query($args); 
    if($loop->have_posts()) { 
     echo '<h2>'.$custom_term->name.'</h2>'; 

     while($loop->have_posts()) : $loop->the_post(); 
      echo '<a href="'.get_permalink().'">'.get_the_title().'</a><br>'; 
     endwhile; 
    } 
} 
+0

返信ありがとうございますが、私は特定のテンプレートでいくつかのクエリを使用してそれが必要です。 –

+0

編集の回答を参照 – GNANA

+0

これはタクソノミの名前に基づいていますが、私はポストのタイプ名に基づいてカテゴリのリストが必要です。 –

0

あなたはこのようなもの使用することができます

$terms = get_terms('products'); 
$count = count($terms); 
if ($count > 0) { 
    echo '<h3>Total products: '. $count . '</h3>'; 
    echo '<ul>'; 
    foreach ($terms as $term) { 
    echo '<li><a href="'.get_term_link($term).'">'.$term->name.'</a></li>'; 
    } 
    echo '</ul>'; 
} 

get_term_linkは()だけでなく、あなたの用語にあなたのリンクを提供します。

関連する問題