Support » Fixing WordPress » Custom Taxonomy Children

  • Hello – I am trying to accomplish the following:

    I’m trying to do something that was fairly easy to achieve with Categories but proves challenging when using Custom Taxonomies.

    When displaying a Taxonomy page, I want to detect whether the taxonomy classification has children.

    If it does have children, I would like to display just the child classifications and their descriptions. I do not want posts to be listed here.

    If it does not have children, then I would like to display the post listing.

    Previously, using categories, I was achieving this using the following code:

    <?php global $ancestor; // Declare global ancestor variable ?>
    $categories = get_categories('child_of=14&order=DESC');
    foreach ($categories as $cat) {
    	if ($cat->cat_ID != 1) { // If category is not uncategorized ...
    	if (cat_is_ancestor_of($ancestor, intval($cat->cat_ID)) == false) { // .. and if the previous category in the loop wasn't the ancestor of this one ... ?>
    		<div class="entries">
     		<div class="entry">
            <h2 class="bold"><a href="<?php echo get_category_link($cat->cat_ID); ?>"><?php echo ($cat->cat_name); ?></a></h2>
    		<?php echo category_description($cat->cat_ID);  ?>
            <p><a href="<?php echo get_category_link($cat->cat_ID); ?>">Read more</a>&nbsp;&raquo;</p>
    		$ancestor = intval($cat->cat_ID); }; // make this category the new ancestor

    Any help would be appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • chymera00


    I’m also having the same problem

    Has anyone solved this?

    I want to do the exact same thing…

    This might work for you.

    $taxonomy_term_id = $wp_query->queried_object_id;
    $taxonomy = 'your-taxonomy-name';
    $taxonomy_children = get_term_children($taxonomy_term_id, $taxonomy);
    if (empty($taxonomy_children)) {
    	echo 'this worked';

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Taxonomy Children’ is closed to new replies.