我正在尝试查询按其父术语分组的帖子标题:
术语名称 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>';
}
提前致谢