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

3 s
3

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):

$json = bbtf_feed_cache( '/api/get_recent_posts/?count=-1&post_type=highline_gallery', 'artists_jsonp' );

if( is_array( $json ) && ! empty( $json ) ) {
    $object  = $json['posts'];
    $artists = array();

    foreach( $object as $item ) {
        $artists[] = array( 'label' => $item['title_plain'], 'value' => $item['title_plain'], 'slug' => $item['slug'], 'id' => $item['id'] );
    }

    $json = json_encode( $artists );    
}

Let me know if this helps…

Leave a Reply

Your email address will not be published. Required fields are marked *