php - Output (echo?) direct children of parent custom taxonomy in a loop -


i'm trying output 1st child level (not parent or grandchildren) custom taxonomies in loop of sort, can add custom fields / thumbnails it.

i created hierarchical custom post type called 'product-type'

and there few levels of custom taxonomies it.

level 1 - snacks

level 2 - chocolates (just showing 1 example)

level 3 - milk chocolates, dark chocolates ..and on.

on parent taxonomy page, i've been able list existing level 2 taxonomies following code:

<?php  $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );  if ($term->parent == 0) {   wp_list_categories('taxonomy=product-type&depth=1&show_count=0 &title_li=&child_of=' . $term->term_id); } else { wp_list_categories('taxonomy=product-type&show_count=0 &title_li=&child_of=' . $term->parent);  } ?> 

the output looks this:

<li class="cat-item cat-item-7"> <a href="..." title="...">chocolates</a> (14) </li> 

my question is, how edit php code above such can output (echo?) only 1st child level (not parent or grandchildren) taxonomy in sort of loop can insert divs or custom fields?

try on size.

https://codex.wordpress.org/function_reference/get_terms

<?php  $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );  if ($term->parent == 0) {       $terms = get_terms( 'product-type', 'child_of='.$term->term_id ); } else {     $terms = get_terms( 'product-type', 'child_of='.$term->parent ); } foreach($terms $term) {     // custom html } ?> 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

Maven Javadoc 'Cannot find default setter' and fails -