I am a big fan of the JSON API plugin. The developer did a great job and I thank him very much. I am learning how to work with json and jquery and am trying to limit the information I get back from an ajax 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.
I managed to narrow down my result with this request url: /?json=get_recent_posts&include=title,url,categories,thumbnail,custom_fields&custom_fields=field1'
plugin url: http://wordpress.org/extend/plugins/json-api/other_notes/
plugin author: http://profiles.wordpress.org/users/dphiffer/
Regards,
Fellow WordPress Developer
I think it really all depends on what the issue with limiting this information is. Do you not want this particular data to be exposed? Do you not want to iterate through so much data? Are you intending on passing this data through a $.getJSON() request? Are you passing this data to a PHP function to handle it?
You can create a new controller to handle this with your own specification, where you’re limiting your JSON output. A good example of a third-party controller is here: wordpress json custom taxonomy problem.
Or if you want an approach that I sometimes have done, where you pass the JSON output to a PHP variable, decode it, filter specific data to a new array, and either use that array as is, o re-encode it back to JSON format. A better example of this (more so pseudo code than code for you to use, as it’s cut, pasted, and reorganized, directly from one of my projects):
Let me know if this helps…
in your themes function file add:
..etc – http://codex.wordpress.org/Post_Thumbnails#Setting_a_Post_Thumbnail
Then in your theme index file add the following inside the has post loop:
Now when you call your JSON an extra field called thumbnail should be displayed.
If you are looking to limit the attachments/images which take up a bulk of the feed when using multiple custom sizes you can use the filter provided by the plugin author to remove certain attachment sizes