Well the title gives it all away...
Here's the code:
$args = array(
"post_type" => "page",
"post_parent" => $cat, // runs through a loop of 5, 128, 130
"posts_per_page" => -1
);
print_r($args);
$postsLang = new WP_Query($args);
while ($postsLang->have_posts()) {
$postsLang->the_post();
$postID = get_the_ID();
array_push($result, $postID);
}
wp_reset_query();
print_r($result);
Here the print_r outputs:
Array ( [post_type] => page [post_parent] => 5 [posts_per_page] => -1 )
Array ( [0] => 30 [1] => 23 )
Array ( [post_type] => page [post_parent] => 128 [posts_per_page] => -1 )
Array ( [0] => 30 [1] => 23 )
Array ( [post_type] => page [post_parent] => 130 [posts_per_page] => -1 )
Array ( [0] => 30 [1] => 23 )
So the $args go into the query correctly, but the outcome is always the same: the IDs of the children of the current page (ID = 5).
I can even set post_parent static to say 128 and still get the children of the current page.
If I remove the post_parent parameter I get all pages (as I should).
I'm having the same issue with get_posts, which makes me think that the syntax is right but that I might be misunderstanding the behaviour of the post_parent parameter?!
Any thoughts much appreciated!!
wp_reset_postdata();
instead ofwp_reset_query();
.