Home Forums Add-ons Gallery Field Reverse lookup a post, that an image is attached to using \"Gallery\"


Reverse lookup a post, that an image is attached to using \"Gallery\"

  • Hey guys, I hope I am explaining this properly.

    I am trying to find the ID of ALL posts that an image is connected to using the Gallery field with ACF.

    For example, if I have an image added to the gallery (field called ‘gallery’) on multiple posts, I want to grab all of the ID’s of the posts when I only have the image.

    I am trying to use a universal function with a loop on the posts.

    I was using the [“uploaded_to”] on the image but it looks like this is just the post it was uploaded to the media folder from, not the ID of the post it is attached to.

  • If your gallery field is not a sub field of a group or repeater then the meta query would look something like this:

    'meta_query' => array(
        'key' => 'gallery_field_name',
        'value' => '"'.$attachment_id.'"',
        'compare' => 'LIKE'

    If it’s a sub field then it gets far more complicated, see the section on sub fields here

  • How do I search an image from my gallery?

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.