List active taxonomy terms

Question

I’m working on tweaking a template which has a filterable masonry layout. I made a taxonomy-categories.php and for the filtering I need the terms of the active taxonomy. The template which I’m using has this code inside it

<ul id="filter">
                <li><a href="#" class="current" data-filter="*" title="">*</a></li>
                <?php
                $categories = get_terms('categories');
                foreach( (array)$categories as $categorie){
                    $cat_name = $categorie->name;
                    $cat_slug = $categorie->slug;
                ?>
                <li><a href="#" data-filter=".<?php echo esc_attr($cat_slug); ?>"><?php echo esc_attr($cat_name); ?></a></li>
                <?php } ?>
            </ul>

As you can see it takes all the terms from the whole taxonomy. I want it to take only the active’s taxonomy sub-terms.

So if I am at URL example.com/portfolio/name_of_cat_one I want to list the children of that category.

I know that I can do that with get_term_by and tweaking a little to achieve my target, but after trying for many hours without success I ended up asking here 🙂

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/list-active-taxonomy-terms/">

List active taxonomy terms</a>
0
, , hambos22 1 month 0 Answers 85 views 0

Leave an answer