Skip to content

Instantly share code, notes, and snippets.

@kenanfallon
Last active May 12, 2016 23:38
Show Gist options
  • Save kenanfallon/42c8d9028a8f82f226a24346c6fce4ea to your computer and use it in GitHub Desktop.
Save kenanfallon/42c8d9028a8f82f226a24346c6fce4ea to your computer and use it in GitHub Desktop.
WP-API - Specify which fields to return in JSON
add_filter( 'rest_prepare_post', 'my_custom_json_fields', 12, 3 );
function my_custom_json_fields( $data, $post, $context ) {
return [
'title' => $data->data['title']['rendered'],
'link' => $data->data['link'],
];
}
credit: https://github.com/WP-API/WP-API/issues/446#issuecomment-212443511
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment