B
B
Boris Belov2018-05-14 21:34:31
WordPress
Boris Belov, 2018-05-14 21:34:31

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:
eee1a4e44b.png
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>
<? } ?>
<? } } ?>

You only need to withdraw
  • Lebron
  • air force
  • hyperdunk
  • Hyperfuse
  • Kobe
  • Kyrie

---
Found the following article https://ru.stackoverflow.com/questions/604477/%D0%...
How do I combine ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Belov, 2018-05-14
@iborisbelov

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 question

Ask a Question

731 491 924 answers to any question