Answer the question
In order to leave comments, you need to log in
How to display term 3 levels in wordpress and without repeats?
Good day.
I tried a bunch of different ways but it didn't work out
Given:
You need to display all term 3 nesting levels (which have posts). But that they do not repeat.
Yes:
Code:
<?
$args = array( 'post_type' => 'novosti', 'taxonomy' => 'brands', );
$args_brands = array( 'orderby' => 'name', 'hide_empty' => 1, 'depth' => 2,);
$categories = get_terms('brands', $args_brands ); if($categories){ foreach ($categories as $cat){
$termID = $cat->term_id;
$taxonomyName = "brands";
$termchildren = get_term_children( $termID, $taxonomyName ); foreach ($termchildren as $child) { $term = get_term_by( 'id', $child, $taxonomyName ); ?>
<li><label><input value=".<?php echo $term->slug; ?>" type="checkbox"><span><?php echo $term->name; ?></span></label></li>
<? } ?>
<? } } ?>
Answer the question
In order to leave comments, you need to log in
Who will be interested in how to get term 3 levels
<? $args = array( 'post_type' => 'novosti', 'taxonomy' => 'brands', );
$args_brands = array( 'orderby' => 'name', 'hide_empty' => 1 );
$all_categories = get_terms('brands', $args_brands );
$third_level = array_filter($all_categories, function ($t) { return $t->parent != 0 && get_term($t->parent, 'brands')->parent != 0;});
$third_level_ids = array_map(function ($t) { return $t->term_id;}, $third_level);
if($third_level){ foreach ($third_level as $third_lev){ ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question