您需要在此处运行两个查询
第一个查询我们将返回所有顶级页面Asia
, Africa
和America
是顶级页面
第二次查询我们将返回顶级页面的所有直接子级
您可以尝试以下方法:
$parent_id_args = [
\'post_parent\' => 0, // Get all top level pages
\'post_type\' => \'page\', // Change if this is a hierarchical custom post type
\'posts_per_page\' => -1, // Get all pages
\'fields\' => \'ids\', // Only get ID\'s
// Add any additional parameters
];
$parent_ids = get_posts( $parent_id_args );
//Make sure we have pages
if ( $parent_ids ) {
$args = [
\'post_type\' => \'page\', // Change according to correct post type
\'posts_per_page\' => -1,
\'post_parent__in\' => $parent_ids, // Get child pages from these parent
// Any additional arguments
];
$q = get_posts( $args );
if ( $q ) {
foreach ( $q as $post ) {
setup_postdata( $post );
the_title();
}
wp_reset_postdata();
}
}