Back to Top

How to get all images from single post in WordPress

Get all image from single post

WordPress is turning into a platform for developing web applications so almost every kind of site you can develop using WordPress and to work with WordPress is pretty easy than the other applications.

Recently, I wanted to develop one slider which display all images from a single post and images are slide into the slider.

As usual, I have used the most common function of WordPress is get_posts function to fetch images from the post and for that I have used ‘post_type’ is equal to attachment.

Now, let’s lay down the WordPress code that does this:

This will load all images attached to the post into the $attachments variable then you can use a foreach loop on them to get your images display.

Above code display, all the images from a single post and you can use those images for a slider or anything else you want to use. ;).

That’s it.I hope this article give you a good idea of how to get all images of single post/page.

Further Reading:

Auto-tagging in WordPress
Hook to change post URL with external one in WordPress
To Exclude Latest Post from the WordPress Loop

Thanks for reading and feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Share: Share on Facebook0Share on LinkedIn0Tweet about this on TwitterShare on Google+1Buffer this pageDigg thisShare on StumbleUpon0Pin on Pinterest0

Comments (5)

  1. Excellent Web page, Maintain the excellent work. Thank you so much.

  2. sir i need this badly , your code is fine on default theme but not working on my Pinterest clone themes. Can you give me php code to put in sidebar so i can use code on all my sites.

    thanks

    1. This code will work for all theme. Provide issue you are facing.

  3. Hi there to every one, it’s really a good for me to visit this web page, it consists of valuable Information.

  4. An outstanding share! I’ve just forwarded this onto a coworker who was doing a little research
    on this. And he actually ordered me lunch simply because I found it for him…

    lol. So let me reword this…. Thank YOU for the meal!!
    But yeah, thanks for spending time to discuss this topic
    here on your web page.

Leave a Reply

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

Most Popular Posts

Table layout using DIV tags

Posted on 3 years ago

Bhumi

GoTo statement in PHP

Posted on 4 years ago

Bhumi

Mysql String Function FIND_IN_SET( )

Posted on 4 years ago

Bhumi

Post via e-mail in WordPress

Posted on 4 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 1 year ago

Bhumi

The Reader’s Poll – August 2014

Posted on 1 year ago

Bhumi

The Reader’s Poll – June 2014

Posted on 2 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 2 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 2 years ago

Bhumi