Get All Attached Images in WordPress

By Avinash

February 20, 2012Web Development1 Comment

Now a days, wordpress is a great platform for blogging and for even CMS also. Also we can customize the wordpress site with very easy and effective ways. This is due to code functionality and flexibility provided by the wordpress team.

As I have mentioned that we can customize this easily. So here is the one of the portion which we can customize using just in-built wordpress functions.

In this article we will see how we can get all attached image to any post. Wordpess has one function get_children() with which we can achieve this functionality very easily.

Have a look at below code block for the same.

$all_images = get_children( array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $post->ID )); var_dump($all_images);
  $all_images = get_children(
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'post_parent' => $post->ID


In above code block $post->ID is the post id of which you want to get all attached images. Here you can see that we have filtered the attachments with mime type so we can get images only.

Hope this trick will be useful to you when you are dealing with these type of customisation part.

Share This Article