From the Codex:
child_of
(integer) Display all categories that are descendants (i.e. children & grandchildren) of the category identified by its ID. There is no default for this parameter. If the parameter is used, the hide_empty parameter is set to false.
和
parent
(integer) Display only categories that are direct descendants (i.e. children only) of the category identified by its ID. This does NOT work like the \'child_of\' parameter. There is no default for this parameter. [In 2.8.4]
因此,首先,如果您只需要立即的decentant,那么您使用的参数是错误的。您需要:
$args = array(\'parent\' => $category_id);
其次,
get_categories
将为您提供一个对象数组,因此您需要这样的内容来提取ID。
$cats = wp_list_pluck($categories,\'cat_ID\');
$args = array (
\'category__and\' => $cats
);
为您提供:
$category_id = get_cat_ID(\'destinations\');
$args = array(\'parent\' => $category_id);
$categories = get_categories($args);
$cats = wp_list_pluck($categories,\'cat_ID\');
$args = array (
\'category__and\' => $cats
);
$recent_posts = new WP_Query($args);