php - How to show only one level sub category? -


i building real estate website have many category 3 4 level child category requirement show 1 level sub category of parent category eg sub1 ,sub2 , sub3 see structure i'm having category

- cat1     - sub1        - secondsub1 - cat2     - sub2       - secondsub2 - cat3    - sub3       - secondsub3    $categories = get_terms(                     'category',                      array('hide_empty' => 0,'parent' => 0,'number' =>3,'order'=> 'asc')                          ); foreach ($categories $category) {             $catname= $category->term_id;  <?php echo get_cat_name( $catname ); // main category ?>  <!-- subcategory code starts here-->          $args = array(                     'type' => 'post',                     'child_of' => $catname,                     'parent' => get_query_var(''),                     'orderby' => 'name',                     'order' => 'asc',                     'hide_empty' => 0,                     'hierarchical' => 1,                     'exclude' => '',                     'include' => '',                     'number' => '5',                     'taxonomy' => 'category',                     'pad_counts' => true );                     $categories = get_categories($args);                     foreach($categories $category) { <a href="<?php echo get_category_link( $category->term_id )?>" title="view posts in <?php echo $category->name?>"><?php $category->name;?></span><!--these sub category-->  } } 

in result under cate1 sub1->secondsub1 because secondsub1 child cat1 want sub1 how can accomplish ? suggestions

use parent instead of child_of:

parent (int|string) parent term id retrieve direct-child terms of.

source: #parameters


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -