Last active
May 12, 2016 23:38
-
-
Save kenanfallon/42c8d9028a8f82f226a24346c6fce4ea to your computer and use it in GitHub Desktop.
WP-API - Specify which fields to return in JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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