Php Wordpress获取术语及其标题

Php Wordpress获取术语及其标题,php,wordpress,custom-post-type,custom-taxonomy,Php,Wordpress,Custom Post Type,Custom Taxonomy,我试图查询按父术语分组的帖子标题: 术语名称1 帖子标题1 帖子标题2 术语名称2 帖子标题1 帖子标题2 e、 t.c 我已经创建了一个自定义帖子和分类法。到目前为止,我的代码贯穿了每个术语名称,但我无法将文章标题分组到它们的父术语下:( 我也不确定在这种情况下是否应该使用新的wp_查询 <?php $term_args = array( 'parent' => 0,

我试图查询按父术语分组的帖子标题:

术语名称1
帖子标题1
帖子标题2

术语名称2
帖子标题1
帖子标题2

e、 t.c

我已经创建了一个自定义帖子和分类法。到目前为止,我的代码贯穿了每个术语名称,但我无法将文章标题分组到它们的父术语下:( 我也不确定在这种情况下是否应该使用新的wp_查询

            <?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>';  
        }

你需要在术语循环中获得帖子

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>';
 }
foreach($terms作为$term){
$music\u args=数组(
“post_type”=>“tf_音乐家”,
'orderby'=>'title',
“订单”=>“ASC”,
“分层”=>false,
“每页帖子数”=>-1,
“您的税收在这里”=>$term->name
);
$music=get_posts($music_args);
回声';
回声';
回音“”;
}
回声“”;
回声';
}
注意:请在中提供分类名称“你的分类法在这里”=> $term->name


非常感谢!我简直是在胡说八道。所以在你有“你的分类法在这里”的地方,我要问的是“类别”参数?@user1575949你可以从
register\u taxonomy()的第一个参数中获得分类法名称
功能当您注册了自定义帖子类型及其类别+1后,我现在在Codex中看到了它