You’ll need to run two queries here
-
First query we will be returning all top level pages (I assume
Asia
,Africa
andAmerica
is top level pages) -
Second query we will get all direct children of the top level pages returned
You can try something like the following:
$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();
}
}