2013-10-03 35 views
0

我想查詢由其父項分組文章標題:WordPress的獲取方面和他們的職稱

術語名稱1
帖子標題1
帖子標題2

術語名稱2
帖子標題1
帖子標題2

etc

我創建了一個自定義文章和分類。到目前爲止,我的代碼通過每個術語名稱上運行,但我無法得到的帖子標題下,他們的父母而言:( 分組我也不能確定我是否應該在這種情況下,使用新wp_query?

  <?php 
      $term_args = array(
       'parent' => 0, 
       'orderby' => 'name', 
       'order' => 'ASC', 
       'hierarchical' => false, 
       'hide_empty' => false 
      ); 
      $terms = get_terms('musicians', $term_args);   

      $music_args = array(
       'post_type' => 'tf_musicians', 
       'orderby' => 'title', 
       'order' => 'ASC', 
       'hierarchical' => false, 
       'posts_per_page' => -1,    
      ); 
      $musicians = get_posts($music_args);  
       foreach($terms as $term){ 
      echo '<div class="inner-content">'; 
       echo '<a name="back-point"></a>';      
       echo '<h2 class="line-spc-sml">'.$term->name.'</h2>';      
       echo '<ul class="inner">'; 

       foreach ($musicians as $musician){ 
        if(has_term('2013','musicians',$musician->ID)) { 
         echo '<li>';     
          echo '<a class="strong" href=', get_permalink($musician->ID), '>', $musician->post_title, '</a>';  
         echo '</li>';         
        } 
        } 

       echo '</ul>'; 
      echo '</div>'; 
     } 

在此先感謝

回答

1

您需要獲得職位方面的循環

foreach ($terms as $term) { 

$music_args = array(
'post_type' => 'tf_musicians', 
'orderby' => 'title', 
'order' => 'ASC', 
'hierarchical' => false, 
'posts_per_page' => -1, 
'your taxonony goes here' => $term->name 
); 

$musicians = get_posts($music_args); 
echo '<div class="inner-content">'; 
echo '<a name="back-point"></a>'; 
echo '<h2 class="line-spc-sml">' . $term->name . '</h2>'; 
echo '<ul class="inner">'; 

foreach ($musicians as $musician) { 

echo '<li>'; 
echo '<a class="strong" href=', get_permalink($musician->ID), '>', $musician->post_title, '</a>'; 
echo '</li>'; 

} 

echo '</ul>'; 
echo '</div>'; 
} 

注意在提供分類名稱「你taxonony到這裏」 => $ term-> name

+0

非常感謝!我真的把我的頭髮拉出來。所以,如果你有'你的taxonony在這裏',我想這是'類別'參數? – Brownrice

+0

@ user1575949當您註冊了您的自定義帖子類型及其類別時,您可以從register_taxonomy()函數的第一個參數中獲得分類名稱 –

+1

+1我現在在Codex [Taxonomy parameters](http:// codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters) – Brownrice

相關問題