2017-09-19 11 views
0

カスタム投稿タイプとカスタム分類を使用してFAQページを作成しています。私はFAQをグループ化するために各分類法のための順序のないリストを作成しようとしています。その順序付けられていないリストでは、最初にリストされたアイテムをタクソノミの名前にして、タクソノミーのすべての質問に対して2番目にリストされたアイテムを繰り返します。これは私がlinkで作業しているページです。Wordpress - カスタムタクソノミでグループ化された投稿を表示するにはどうすればよいですか?

正当なタクソノミーではなく、現在投稿を複製しています。あなたのquery_post

     <?php 
         // get all the categories from the database 
         $cats = get_terms(array(
          'taxonomy' => 'faq_categories', 
         )); 

         // loop through the categories 
         foreach ($cats as $cat) { 
          // setup the category ID 
          $cat_id = $cat->term_id; 
         ?> 

           <!-- Make a header for the category --> 
         <ul id="<?php echo $cat->slug; ?>" class="cd-faq-group"> 
          <li class="cd-faq-title"> 
           <h2>Questions <?php echo $cat->name; ?></h2> 
          </li> 

          <?php 

          // create a custom wordpress query 

          query_posts(array(
           'post_type' => 'faqs', 
           'tax_query' => array( 
            array( 
             'taxonomy' => 'faq_categories', //or tag or custom taxonomy 
             'field' => 'slug', 
             'terms' => 'for-women' 
            ) 
           ) 
          )); 

          // start the wordpress loop! 
          if (have_posts()) : while (have_posts()) : the_post(); ?> 

          <li> 
           <a class="cd-faq-trigger" href="#0"><?php the_title(); ?></a> 
           <div class="cd-faq-content"> 
            <?php the_content(); ?> 
           </div> 
          </li> 

          <?php endwhile; endif; // done our wordpress loop. Will start again for each category 

          wp_reset_postdata(); 
          ?> 


         </ul> 
         <?php } // done the foreach statement ?> 

答えて

0

$catsアレイを繰り返してもクエリは変更されません。おそらく、用語配列の値を$cat->slugに変更すると、より良い結果が得られます。

0

、あなたのtax_queryfieldterm_idする必要がありますし、あなたのterms代わりにハードコードされた用語で、あなたの$cat_id変数に代入すること。

0

sooooありがとうございます。あなたは私が見逃していたことについて、どちらも素晴らしい洞察を与えてくれました。私は今これを解決しました。これがあなたの提案を考慮して解決する方法です。

     <?php 

          $cats = get_terms( 
           array(
            'taxonomy' => 'faq_categories', 
            'orderby' => 'term_id', 
            'order' => 'ASC' 
           ) 
          ); 

          foreach ($cats as $cat) : 
         ?> 


         <ul id="<?php echo $cat->slug; ?>" class="cd-faq-group"> 
          <li class="cd-faq-title"> 
           <h2>Questions <?php echo $cat->name; ?></h2> 
          </li> 
         <?php 

          $questions = new WP_Query(
           array(
            'category_name' => $cat->slug 
           ) 
          ); 

          $questions = new WP_Query(array(
           'post_type' => 'faqs', 
           'order' => 'ASC', 
           'tax_query' => array( 
            array( 
             'taxonomy' => 'faq_categories', 
             'field' => 'slug', 
             'terms' => array($cat->slug), 
            ) 
           ) 
          )); 
         ?> 

         <?php if ($questions->have_posts()) : while ($questions->have_posts()) : $questions->the_post();?> 

          <li> 
           <a class="cd-faq-trigger" href="#0"><?php the_title(); ?></a> 
           <div class="cd-faq-content"> 
            <?php the_content(); ?> 
           </div> 
          </li> 

          <?php endwhile; ?> 

          <?php wp_reset_postdata(); ?> 
         <?php endif; ?> 
関連する問題