I have a post that contain images, let’s say image with id 19, 12, 10.
I attach image 19 first, 12 below the first and 10 as the last, and I need to retrieve them. I

$post_images = get_children( array(
    'post_parent' => $id,
    'post_status' => 'inherit',
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
));

But i receive them sorted by id (10,12,19), how i get them with the order as i needed

2 Answers
2

The documentation for get_children isn’t great (at the time of this answer), however get_children is simply a wrapper for get_posts(). This means that orderby and order are valid arguments for your query.

When you ask, “how i get them with the order as i needed“, is the property you wish to order them by a valid orderby value? If so, your function call might look like this:

$post_images = get_children( array(
    'post_parent' => $id,
    'post_status' => 'inherit',
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'orderby' => 'title'
    'order' => 'ASC',
));

Leave a Reply

Your email address will not be published. Required fields are marked *