Get categories of the custom taxonomy -wordpress
-
I have a custom WordPress theme. I have a custom taxonomy – taluka added to the regular posts with default category. There are different posts with taluka taxonomy and default categories. I want to display the categories to the respective taxonomy
<ul> <li>-Taluka 1 <ul> <li>- Category1 </li> <li>- Category2</li> <li>- Category3</li> <ul> </li> <li>-Taluka 2 <ul> <li>- Category2 </li> <li>- Category3</li> <li>- Category4</li> <ul> </li> <li>-Taluka 3 <ul> <li>- Category1 </li> <li>- Category4</li> <li>- Category5</li> <ul> </li> </ul>
I tried the following code but it display all the categories
$terms = get_terms('taluka', array('hide_empty'=> true, 'orderby' => 'title', 'order'=> 'ASC',)); $categories = get_categories($terms); $cat_slug = $category->slug; echo '<ul class="test">'; foreach ( $terms as $term ) { $termname = strtolower($term->name); $termname = str_replace(' ', '-', $termname); echo '<li>'. $term->name ; if ( !empty( $categories ) && !is_wp_error( $categories ) ){ echo '<ul class="subtest">'; foreach ( $categories as $category ) {; echo '<li data-filter="'.$category->slug.'">'.$category->name.'</li>'; } echo '</ul>'; } echo '</li>'; }; echo '</ul>';
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Get categories of the custom taxonomy -wordpress’ is closed to new replies.