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(
        			'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!