Support

Account

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

Solving

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(
      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 https://www.advancedcustomfields.com/resources/query-posts-custom-fields/

  • 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.