How do I sort (order) the results from `get_children()`?

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 Comment