I would like to get 2 images in media by their IDs. If I want to get only one image I would use this code

$args = array(
    'p' => 1,
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'no_found_rows' => true,
    'posts_per_page' => 2,
    'post_status' => 'any'

$query = new WP_Query($args);

How can I do it for 2 images, without double queries?

It would be great if I can pass an array with IDs but 'p' according to Codex can be only integer

    'p' => array(1,2),

p (int) – use post id. Default post type is post.

Read more here: WP_Query attachments by multiple IDs


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: