Help with 4.6. Attachment response object in JSON API plugin

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 Comment