• Resolved wywarren

    (@wywarren)


    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://www.ads-software.com/plugins/json-api/

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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

    Thread Starter wywarren

    (@wywarren)

    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://www.ads-software.com/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

    (@wywarren)

    I guess this is resolved but should be updated according in the actual plugin in a later release.

    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.