WordPress.org

Ready to get started?Download WordPress

Forums

JSON API
Help with (4.6. Attachment response object) (2 posts)

  1. generalChaos
    Member
    Posted 2 years ago #

    I am a big fan of the JSON API plugin, great job and thanks so much. I am learning how to work with json and jquery and am trying to limit the information I get back from a request. I have been able to use the include and custom field options successfully but amd falling a little short understanding 4.6. Attachment response object. Is there a way to limit the result to only provide thumb images? If so, can anyone provide an example of the syntax. I am not sure how to address these objects in the query string. Any help would be awesome. Let me know if I need to clarify anything.

    Regards,
    Fellow JSON API fan

    http://wordpress.org/extend/plugins/json-api/

  2. cmunns
    Member
    Posted 2 years ago #

    You can use the filter they provide to unset whatever sizes you don't need

    add_filter('json_api_encode', 'my_encode_attachments');
    
    function my_encode_attachments($response) {
      if (isset($response['posts'])) {
        foreach ($response['posts'] as $post) {
    		foreach ($post->attachments as $attachment){
    			unset($attachment->images['full']);
    			unset($attachment->images['thumbnail']);
    		}
        }
      }
      return $response;
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags