Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Am hoping someone can help me pull out a single custom category name and show it on my custom post page. I've created a new custom post type 'Itinerary' as well as some new custom categories (terms):

Experience

  • Water Sports
  • Hiking Adventures
  • Mountain Biking ...

Destination

  • Australia
  • Canada
  • South America ...

Each Itinerary has 2 categories applied to it, for example: Itinerary 'Coastal Walks' is categorised as Hiking Adventures and Australia.

I would like to display in my single itinerary page the name of the child Destination e.g. Region: Australia (or whatever child destination is selected)

I've tried using this:

<?php echo the_terms( $post->ID, 'trip_cat', 'Region: ', ', ', ' ' );   ?>

but this displays all the categories selected - I'm trying to display only the child of category Destinations.

Can anyone please help? :)

share|improve this question

1 Answer 1

You can use get_term_children function.

For Example:

<?php
$termID = 10;
$taxonomyName = "region";
$termchildren = get_term_children( $termID, $taxonomyName );

echo '<ul>';
foreach ($termchildren as $child) {
    $term = get_term_by( 'id', $child, $taxonomyName );
    echo '<li><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
?>
share|improve this answer
    
Thanks for your help! I can get this function working, but it displays all regions in a list e.g. Australia Canada South America ... I need the function to somewhow reference the single page, check what location is selected e.g. Australia, and show only that destination. –  Emj Ray Mar 13 '13 at 0:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.