WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
You should really try to contact the plugin author directly. He will be far more qualified to support this plugin than we will be. – EAMann Oct 18 '11 at 16:41

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...

share|improve this answer

in your themes function file add:

add_theme_support( 'post-thumbnails' );    
set_post_thumbnail_size( 50, 50, true ); // 50 pixels wide by 50 pixels tall, crop mode

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

// check if the post has a Post Thumbnail assigned to it.    
if ( has_post_thumbnail() ) {

Now when you call your JSON an extra field called thumbnail should be displayed.

share|improve this answer

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

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){
  return $response;
share|improve this answer
Simply set the values in "Admin UI" » "Settings" » "Media" to 0 and they will get skipped on creation. – kaiser Oct 2 '12 at 18:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.