Title: Attachments empty
Last modified: August 22, 2016

---

# Attachments empty

 *  Resolved [wywarren](https://wordpress.org/support/users/wywarren/)
 * (@wywarren)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/attachments-empty/)
 * If I upload and attach a featured image for a new post the attachment shows up
   for that post. If I upload any more images along with that post they also show
   up in that post’s attachments. If I make a new post with an existing image in
   the media database, the queries will show that the post has no attachments.
 * [https://wordpress.org/plugins/json-api/](https://wordpress.org/plugins/json-api/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [xiffy](https://wordpress.org/support/users/xiffy/)
 * (@xiffy)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/attachments-empty/#post-5624976)
 * Do you have a multi-site install? Does this install use paths, not subdomains?
   I was having the same problem, and noticed that the JSON-API for attachments 
   only works on the main blog (residing at ABSPATH)
 * If you donwload version 1.0.7 (2011-01-27) and use models/attachment.php from
   that zip, your problem will be resolved.
    I will file a bug (and waited way to
   long to upgrade…) hth
 *  [xiffy](https://wordpress.org/support/users/xiffy/)
 * (@xiffy)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/attachments-empty/#post-5624978)
 * [@wywarren](https://wordpress.org/support/users/wywarren/), i’ve suggested a 
   patch for this bug in this post: [https://wordpress.org/support/topic/modelsattachmentphp-bug-with-getting-attachments-on-folder-mulit-site-installs](https://wordpress.org/support/topic/modelsattachmentphp-bug-with-getting-attachments-on-folder-mulit-site-installs)
 *  Thread Starter [wywarren](https://wordpress.org/support/users/wywarren/)
 * (@wywarren)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/attachments-empty/#post-5624984)
 * Nope it’s actually a single site. Turns out if you have a different wordpress
   install ur; than your site url it could cause this. Turns out the fix is this:
   [https://wordpress.org/support/topic/thumbnails-not-included-for-attachment-fix?replies=5](https://wordpress.org/support/topic/thumbnails-not-included-for-attachment-fix?replies=5)
 *     ```
       function query_images() {
           $sizes = array('thumbnail', 'medium', 'large', 'full');
           if (function_exists('get_intermediate_image_sizes')) {
             $sizes = array_merge(array('full'), get_intermediate_image_sizes());
           }
           $this->images = array();
           $upload_dir = wp_upload_dir();
           foreach ($sizes as $size) {
             list($url, $width, $height) = wp_get_attachment_image_src($this->id, $size);
             $filename = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $url);
             if (file_exists($filename)) {
               list($measured_width, $measured_height) = getimagesize($filename);
               if ($measured_width == $width &&
                   $measured_height == $height) {
                 $this->images[$size] = (object) array(
                   'url' => $url,
                   'width' => $width,
                   'height' => $height
                 );
               }
             }
           }
         }
       ```
   
 * Just replace that function located in models/attachment.php and you will get 
   back your thumbnails (featured image) in JSON API
 *  Thread Starter [wywarren](https://wordpress.org/support/users/wywarren/)
 * (@wywarren)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/attachments-empty/#post-5624985)
 * I guess this is resolved but should be updated according in the actual plugin
   in a later release.
 *  [rutgervanw](https://wordpress.org/support/users/rutgervanw/)
 * (@rutgervanw)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/attachments-empty/#post-5625006)
 * I had a similar problem, but I’m using the WP Read Only plugin (I’m running WordPress
   on Heroku). This plugin makes sure all images are uploaded to S3. The thumbnails
   were null also.
 * I rewritten the above function and deleted the checks whether the file exists.
   It works now, but obviously does not check for the file’s existence:
 *     ```
       function query_images() {
           $sizes = array('thumbnail', 'medium', 'large', 'full');
           if (function_exists('get_intermediate_image_sizes')) {
             $sizes = array_merge(array('full'), get_intermediate_image_sizes());
           }
           $this->images = array();
           $home = get_bloginfo('url');
           $upload_dir = wp_upload_dir();
           $basedir = $upload_dir['basedir'];
           $file = get_post_meta($this->id, '_wp_attached_file', true);
   
           foreach ($sizes as $size) {
             list($url, $width, $height) = wp_get_attachment_image_src($this->id, $size);
             $filename = $basedir . '/' . str_replace(basename($file), basename(parse_url($url, PHP_URL_PATH)), $file);
             list($measured_width, $measured_height) = getimagesize($filename);
             $this->images[$size] = (object) array(
               'url' => $url,
               'width' => $width,
               'height' => $height
             );
           }
         }
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Attachments empty’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/json-api.svg)
 * [JSON API](https://wordpress.org/plugins/json-api/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/json-api/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/json-api/)
 * [Active Topics](https://wordpress.org/support/plugin/json-api/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/json-api/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/json-api/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [rutgervanw](https://wordpress.org/support/users/rutgervanw/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/attachments-empty/#post-5625006)
 * Status: resolved