Home › Forums › Add-ons › Gallery Field › “Reverse Lookup” via Attachment Custom Field › Reply To: “Reverse Lookup” via Attachment Custom Field
Thanks for the help. This makes sense to me, but I’m getting bool(false) when I var_dump the first query.
Using this:
$image_meta_image_id = $_GET["image_id"];
echo $image_meta_image_id; // doing this to make sure it's getting it from the URL.
// first you do a query for attachments looking for the exact image_meta_image_id
$args = array(
'fields' => 'ids', // return only IDs to use in the next query
'posts_per_page' => 1, // there should only be one image
// with this "image_meta_image_id"
'post_type' => 'attachment',
'meta_query' => array(
array(
'key' => 'image_meta_image_id',
'value' => $image_meta_image_id
)
)
);
$attachment_query = new WP_Query( $args );
$attachments = $attachment_query->posts();
echo "<pre>";
var_dump( $attachments );
echo "</pre>";
I’ve confirmed that the image I’m trying to get has the correct value for its image_meta_image_id field (It’s 17574).
Any ideas?
Thanks a bunch for the help!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.