Support

Account

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.