WordPress.org

Ready to get started?Download WordPress

Forums

How to pull last 10 posts that have image attachments? (4 posts)

  1. Chandra M
    Member
    Posted 4 years ago #

    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!

  2. MichaelH
    Member
    Posted 4 years ago #

    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

  3. Chandra M
    Member
    Posted 4 years ago #

    Hey Michael,

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

    I will try the first one.

  4. Chandra M
    Member
    Posted 4 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.