I have a set of schools in a custom post type with locations ordered as follows:
London
- 1 Oxford Road
- 2 Cambridge Road
Paris
- 1 Napoleon Road
- 2 Tower Road
How do I change the following so that the location parent is outputted instead of the location child:
// 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;
Thank you.
I didn’t test the following script, but I hope it will bring you a step forward to the solution.
Change ‘work_categories’ to your taxonomy name – the code below is tested but won’t work on the older PHP versions such 5.3.