Skip to content

Instantly share code, notes, and snippets.

/wp

Created Jun 11, 2015
Embed
What would you like to do?
function qod_remove_extra_data( $data, $post, $context ) {
if ( $context !== 'view' || is_wp_error( $data ) ) {
return $data;
}
unset( $data['terms'] );
unset( $data['type'] );
unset( $data['modified'] );
unset( $data['status'] );
unset( $data['author'] );
unset( $data['parent'] );
unset( $data['format'] );
unset( $data['slug'] );
unset( $data['guid'] );
unset( $data['menu_order'] );
unset( $data['comment_status'] );
unset( $data['ping_status'] );
unset( $data['sticky'] );
unset( $data['date_tz'] );
unset( $data['date_gmt'] );
unset( $data['modified_tz'] );
unset( $data['modified_gmt'] );
unset( $data['meta'] );
unset( $data['date'] );
unset( $data['ID'] );
unset( $data['link'] );
return $data;
}
add_filter( 'json_prepare_post', 'qod_remove_extra_data', 10, 3 );
@andyadams

This comment has been minimized.

Copy link

@andyadams andyadams commented Jun 15, 2015

What version of the WP JSON API are you using with this code? I'm using version 1.2.2 and it works for me.

@daliborgogic

This comment has been minimized.

Copy link

@daliborgogic daliborgogic commented Jan 8, 2016

// WP REST API v2

// Prepare Pages 
add_filter('rest_prepare_page', 'remove_extra_data', 12, 3);
function remove_extra_data($data, $post, $context) {
  if ($context !== 'view' || is_wp_error ($data)) {
    unset ($data->data['excerpt']);
    // ...
    return $data;
  }
}

// Prepare Posts
add_filter('rest_prepare_post', 'remove_extra_data', 12, 3);
function remove_extra_data($data, $post, $context) {
  if  $context !== 'view' || is_wp_error($data)) {
    unset($data->data['excerpt']);
    // ...
    return $data;
  }
}

// For Custom Post Type: add_filter('rest_prepare_{$post_type}', 'remove_extra_data', 12, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.