0
for Indoor
-for bedroom
--TFL
---8u
---9u
--MFL
---10u
---11u
-for Kitchen
--ABC
---4u
---5u
--XYZ
---6u
---7u

These are the category listing...

when user click on the for bedroom at that time show only TFL and MFL and same when click for kitchen at that time show only xyz and abc...

and then

user click on TFL at that time show only 8u and 9u same user click on xyz at that time show only 4u and 5u...

this all are category listing

===========================

<?php
$vnkings_id = get_queried_object()->term_id;
$term_id = $vnkings_id; // id của term cha vừa tìm 
$taxonomy_name = 'product-category'; // post type của bạn, ví dụ products
$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>';
?> 
2
  • And your question is?
    – cjbj
    Jun 14 '16 at 12:55
  • I want this type of when user click on the for bedroom at that time show only TFL and MFL and same when click for kitchen at that time show only xyz and abc... and then user click on TFL at that time show only 8u and 9u same user click on xyz at that time show only 4u and 5u... but not work this code Jun 14 '16 at 12:59
0

With get_term_children you are retrieving a flat array of all child terms. What you want is an array with only the first child terms. Unfortunately there is no immediate way to retrieve this, so it has to be done in two steps:

$parent_term = get_term_by('slug', 'bedroom', 'your_taxonomy_slug');

This gives you the 'bedroom' taxonomy term. Now you can use this to find the direct children:

$children = get_terms( 'your_taxonomy_slug', array( 'parent' => $parent_term->term_id ) );

This returns an array of child terms.

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.