Home › Forums › Add-ons › Gallery Field › “Reverse Lookup” via Attachment Custom Field › Reply To: “Reverse Lookup” via Attachment Custom Field
Ended up cheating by using this:
$image_meta_image_id = $_GET["image_id"];
global $wpdb;
$attachment_query = "SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( ( wp_postmeta.meta_key = 'image_meta_image_id' AND wp_postmeta.meta_value = '" . $image_meta_image_id . "' ) ) AND wp_posts.post_type = 'attachment' AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 1";
$attachments = $wpdb->get_results( $attachment_query );
Still unsure why the WP query doesn’t work, but this is good enough. Thanks 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.