Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Last active June 1, 2017 11:18
Show Gist options
  • Save daliborgogic/5cbdd68114d2b2a46ac5 to your computer and use it in GitHub Desktop.
Save daliborgogic/5cbdd68114d2b2a46ac5 to your computer and use it in GitHub Desktop.
WP REST API v2
// 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