• Resolved jrcollins

    (@jrcollins)


    The code below is part of a block of code I’m using in a custom category template to display child categories of the current category. Instead of getting all the child categories I would like to filter them by id, name or slug. Can anyone tell me how to do this?

    $catpage = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
    $catnum = 5;
    $offset = ($catnum * $catpage) - 5;
    $cat = get_category( get_query_var( 'cat' ) );
    $cat_id = $cat->cat_ID;
    
    get_categories(
            array(
            'parent' => $cat_id,
            'orderby' => 'id',
            'order' => 'DESC',
            'hide_empty' => '0',
            'number' => $catnum,
            'offset' => $offset,
            'paged' => $catpage
        )
    );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Yes there is a include property you can make use of it just :

    get_categories(
            array(
            'include' => array(1,54,6,9), // add here the ids of categories you want to display
            'parent' => $cat_id,
            'orderby' => 'id',
            'order' => 'DESC',
            'hide_empty' => '0',
            'number' => $catnum,
            'offset' => $offset,
            'paged' => $catpage
        )
    );
    Thread Starter jrcollins

    (@jrcollins)

    Ok, that’s easy. Thanks for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to get child categories by id?’ is closed to new replies.