这将为您获取所有子页面的帖子数据:
$args = array(
\'post_type\' => \'page\',
\'post_parent__not_in\' => array(0),
\'no_found_rows\' => true,
);
$child = new WP_Query($args);
var_dump(wp_list_pluck($child->posts,\'post_title\')); // debugging only
然后将ID传递给
wp_list_pages()
:
$args = array(
\'post_type\' => \'page\',
\'post_parent__not_in\' => array(0),
\'no_found_rows\' => true,
);
$child = new WP_Query($args);
$ids = wp_list_pluck($child->posts,\'ID\');
$ids = implode($ids,\',\');
$args = array(
\'include\' => $ids,
);
wp_list_pages($args);
或者,甚至更干净:
$args = array(
\'post_type\' => \'page\',
\'post_parent__not_in\' => array(0),
\'no_found_rows\' => true,
\'fields\' => \'ids\'
);
$child = new WP_Query($args);
$args = array(
\'include\' => $child->posts,
);
wp_list_pages($args);
请注意,对该代码没有错误检查。
我会看看我是否能找到一种干净的方法来使用过滤器。稍后再查看。