I'm working on a project where I need to query all of the image attachments and then organize them based on the date the post they were attached to was published.
The query below worked well, except that the order from
$post_image_query was not being maintained in the output from
So my question was how can I query all attachments and order them by the publishing date of their parents?
// Get All Post IDs $post_image_query = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1, 'orderby' => 'date', 'fields' => 'ids' ) ); // Get All Attachments of Posts from $post_image_query $the_query = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_parent__in' => $post_image_query->posts ); );