Wordpress: how to get first level of children from

2019-08-01 09:02发布

问题:

I want to know if has a function that return only the first level of subcategories children.

Cat 1
   Sub-1.1
   Sub-1.2
       Sub-1.2.1
Cat 2
   Sub-2.1

Here I want only: Sub-1.1, Sub-1.2 and Sub-2.1

Cause using get_categories with child_of parameter brings me all children until the last node:

get_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID);

Thanks

回答1:

Please try

wp_list_categories(array('depth' => 2));