0

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? :)

0

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>';
?>
  • 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
0

Stop treating "Destination" and "Experience" as subsets of the same taxonomy type - those should be two separate taxonomy types. (trip_region and trip_theme maybe?)

Once they're handled as two separate taxonomies, then you can do what you're trying to do:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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