WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

this code to display subcategories in categories page

i need to view subcategories sort as id subcategories can anyone update this code to view subcategories order by id

if(is_category()) {

    $breakpoint = 0;
    $thiscat = get_term( get_query_var('cat') , 'category' );
    $subcategories = get_terms( 'category' , 'parent='.get_query_var('cat') );

    if(!empty($subcategories)) {
        foreach($subcategories as $subcat) {
            if($thiscat->term_id == $subcat->term_id) $current = ' current-cat'; else $current = '';
        $items .= '

             <span class="sidebar_content_morzak"><a href="'.get_category_link( $subcat->term_id ).'" title="">'.$subcat->name.'</a></span>

        echo "$items";

share|improve this question

If you want to order by id you can replace

 $subcategories = get_terms( 'category' , 'parent='.get_query_var('cat') );


     'orderby' => 'id', 
     'order' => 'ASC',  
 $subcategories = get_terms( 'category' , $args);

You can read more about the available parameters in the Codex here:


share|improve this answer
thanks you . its work very good now – user2075379 Feb 23 '13 at 20:02
ok great it worked out for you ;-) – birgire Feb 23 '13 at 20:29
ps: you should consider marking the question as resolved, thanks ;-) – birgire Mar 7 '13 at 11:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.