0

I have a problem with displaying taxonomy on the site taxonomy.php I have such a structure:

  • Level 1
    • sub-level 1
      • sub-sub-level 1
      • sub-sub-level 2
    • sub-level 2
      • sub-sub-level 1
      • sub-sub-level 2

I do not know how to display custom taxonomy in some way. I would also like to click on sub-level 1 to display sub-level 1 and sub-sub-level 2, and if no child is found, the posts from this clicked taxonomy showed up. Please help me

1
  • Where do you want to display the result of the click ? on the same page with AJAX ?
    – mmm
    Jan 11 '18 at 20:21
1

There is solved:

$taxonomy_name = 'listing_category';
$queried_object = get_queried_object();
$term_id = $queried_object->term_id;

$termchildren = get_terms( $taxonomy_name, array( 'parent' => $term_id, 'hide_empty' => false ) );

echo '<ul>';
   foreach ( $termchildren as $child ) {
       echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $child->name . '</a></li>';
   }
echo '</ul>';

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.