WordPress.org

Support

Support » Plugins and Hacks » How to pull last 10 posts that have image attachments?

How to pull last 10 posts that have image attachments?

  • Hi,

    Now sure where to post this but I thought this might be more of a hack as I can’t seem to find it.

    What I want to achieve is run a query and show the last 10 posts. This is simple. Now the complex part is I want to pull the last 10 posts that has attachments.

    So, in the last 10 posts if only 4 has attachments, I don’t just want to pull 4 posts, I want to select the other latest 6 posts that has attachments. Hope that makes sense.

    Is there something like..

    query_posts('showposts=10&has_attachment=true');

    It would be great if someone has any suggestions to it.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Not sure about getting the last 10 posts–you may have to get the attachments, then put each post ID into an array until you have 10 posts. But , try:

    query_posts('showposts=10&post_type=attachment');

    Related:
    Function_Reference/get_children

    Hey Michael,

    Thanks, but I don’t get anything if I do that.

    I will try the first one.

    well.. didn’t get the idea.. anyone? I don’t want to pull all the attachments.. I want to pull 1 attachment (image) from each post that has the image and show 10 of them.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to pull last 10 posts that have image attachments?’ is closed to new replies.
Skip to toolbar