post_parent array doesn't work

I have a problem. I created a shortcode to show a galerie. I used query_posts to fetch all posts of a parent post and get the data from there:

function galerie_baureihe() { 
   $parent_id = get_the_id($post->post_parent); $page_id = $parent_id; 
   query_posts(array('post_type' => 'page', 'post_parent' => $page_id, 'orderby' => 'title', 'order' => ASC,  'posts_per_page' => '9999'));
   if (have_posts()) :
      while (have_posts()) : the_post();
         $return_string .= '<div class="dynamische-galerie"><div class="col-4"><div class="dynamische-galerie-wrapper"><a href="'.get_permalink().'">'.get_the_post_thumbnail( $post_id, array(285,200) ).'</a><div class="dynamische-galerie-caption"><a href="'.get_permalink().'"><b>'.get_the_title().'</b><br>'.number_format(get_field( 'nettogrundflaeche' ),2,',','.').'<span>&nbsp;m²</span></a></div></div></div></div>';
      endwhile;
   endif;
   wp_reset_query();
   return $return_string;
}

add_shortcode( 'galerie_baureihe', 'galerie_baureihe' );

This works fine, but now i need such a shortcode on an other side and i need 'post_parent' => array(376, 379), instead of 'post_parent' => $page_id,

Here is the other code:

function galerie_klassisch_wohnen() { 
   query_posts(array('post_type' => 'page', 'post_parent' => array(376, 379), 'orderby' => 'title', 'order' => ASC,  'posts_per_page' => '9999'));
   if (have_posts()) :
      while (have_posts()) : the_post();
         $return_string .= '<div class="dynamische-galerie"><div class="col-4"><div class="dynamische-galerie-wrapper"><a href="'.get_permalink().'">'.get_the_post_thumbnail( $post_id, array(285,200) ).'</a><div class="dynamische-galerie-caption"><a href="'.get_permalink().'"><b>'.get_the_title().'</b><br>'.number_format(get_field( 'nettogrundflaeche' ),2,',','.').'<span>&nbsp;m²</span></a></div></div></div></div>';
      endwhile;
   endif;
   wp_reset_query();
   return $return_string;
}

add_shortcode( 'galerie_klassisch_wohnen', 'galerie_klassisch_wohnen' );

But it seems i cant use an array for post_parent. If i use 'post_parent' => 376, it works but not with 'post_parent' => array(376, 379),

I hope you guys understand my bad english. What can I do to get the shortcode to work with the array?

Solutions Collecting From Web of "post_parent array doesn't work"

It’s not recommended to use query_posts(), check for example this warning note in the Codex:

This function isn’t meant to be used by plugins or themes. As
explained later, there are better, more performant options to alter
the main query. query_posts() is overly simplistic and problematic way
to modify main query of a page by replacing it with new instance of
the query. It is inefficient (re-runs SQL queries) and will outright
fail in some circumstances (especially often when dealing with posts
pagination). Any modern WP code should use more reliable methods, like
making use of pre_get_posts hook, for this purpose.

Regarding the post parents array, you’re using a wrong parameter. There exists the post_parent__in parameter that can handle an array input.

So please try this secondary query, instead of your current one:

$query = new WP_Query( 
    array(
        'post_type'       => 'page', 
        'post_parent__in' => array(376, 379), 
        'orderby'         => 'title', 
        'order'           => ASC,  
        'posts_per_page'  => 9999
    )
);

You should also consider initializing your variable with $return_string = ''; to avoid the PHP Undefined variable notice when you use the .= for string concatenation.

Then replace wp_reset_query() with wp_reset_postdata(), to reset the $post variable of the main query.