Display only first level children of my custom taxonomy categories

I’d like to display only first level children of my custom taxonomy categories
I’am using wp 3.8

I’ve something like for my taxonomy “listing_category”:
Category 1
SubCattegoy1
Subsub category1

Read More

I’d like to display only a link to “sub category1” when I’am on “Category 1” (not “subsub category1”). With the code below It displays all sub cat and subsub cat :

$taxonomy_name = 'listing_category';
$queried_object = get_queried_object();
$term_id = $queried_object->term_id;
$termchildren = get_term_children( $term_id, $taxonomy_name );
  echo '<ul>';
   foreach ( $termchildren as $child ) {
   $term = get_term_by( 'id', $child, $taxonomy_name );
  echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a></li>';
 }
  echo '</ul>';

Any ideas to help me ? Thanks

Related posts

1 comment

  1. Try the following code:

    $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>';
    

Comments are closed.