How to pass multiple ids to post_parent?

2019-09-09 08:10发布

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'
    )
    );

标签: wordpress
1条回答
叛逆
2楼-- · 2019-09-09 08:29

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

查看更多
登录 后发表回答