How to pass multiple ids to post_parent?

2019-09-09 08:27发布

问题:

So i need to pass multiple values but i dont know how? Any suggestion?

$myarray = array('144', '246');

$images = get_children(array(
    'title_li'     => '',
    'post_parent'       => $myarray,
    'sort_order'    => 'DESC',
    'sort_column'   => 'menu_order'
    )
    );

回答1:

You can do this with WP_Query object :

$children_query = new WP_Query(array(
    'post_type'       => 'attachment',
    'orderby'         => 'menu_order',
    'order'           => 'DESC',
    'post_parent__in' => array('144', '246')
));
if($children_query->have_posts()){
    while($children_query->have_posts()){
        $children_query->the_post();
        // your display
    }
    wp_reset_postdata();
}

This will look for all media attached to any post of the array



标签: wordpress