WordPress.org

Ready to get started?Download WordPress

Forums

Get a list of all the post associated with an attachment (5 posts)

  1. surfsup74
    Member
    Posted 1 year ago #

    Is there a way to display a list of all the posts an attachment is associated with (all the posts in which you can find the image on my website).

    I want to say for example 'This image can be found in [post title A] and [post title B]

    I would also like the post titles to be wrapped in an anchor with the url of the post.

    This may or may not be possible? I look forward to finding out though, so that I can move on!

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Each attachment will only be associated (attached) to one post. get_permalink($post->post_parent) will return the attachment's parent Post or Page if used inside the Loop.

  3. surfsup74
    Member
    Posted 1 year ago #

    Thanks Esmi,

    Is there a way of showing multiple posts (if an attachment is used in more than one post)?

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    No. WordPress only stores one Post/Page attachment per media file - usually the page that the file was first inserted into or the page being edited when the attachment file was uploaded. No further uses of the file are stored.

  5. surfsup74
    Member
    Posted 1 year ago #

    Ok - thanks for the heads up. I can now move on.

Topic Closed

This topic has been closed to new replies.

About this Topic