我有一组自定义帖子类型的学校,位置顺序如下:
London
- 1 Oxford Road
- 2 Cambridge Road
Paris
- 1 Napoleon Road
- 2 Tower Road
如何更改以下内容以便输出位置父级而不是位置子级:
// begin loop
$args = array('post_type' => 'school');
query_posts($args); if ( have_posts() ) : while ( have_posts() ) : the_post();
// variable for location
$location = get_the_term_list( $post->ID, 'location', '', ', ', '' );
// output
echo get_the_title() . ' - ' . $location;
// end loop
endwhile; endif;
谢谢。
我没有测试以下脚本,但我希望它能让您在解决方案上迈出一步。
// begin loop
$args = array('post_type' => 'school');
query_posts($args); if ( have_posts() ) : while ( have_posts() ) : the_post();
// variable for location
$term_list = '';
$terms = get_the_terms( $post->ID, 'location' );
$prefix = '';
foreach( $terms as $term ) {
$parent_term = get_term( $term->parent, 'location' );
$term_list .= $prefix . $parent_term->name . ' - ' . $term->name;
$prefix = ', ';
}
// output
echo get_the_title() . ' - ' . $term_list;
// end loop
endwhile; endif;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)