Skip to content

Instantly share code, notes, and snippets.

@rowej83
Last active April 25, 2017 13:53
Show Gist options
  • Save rowej83/e11007c309ce7bc20d6736992a1b4f8d to your computer and use it in GitHub Desktop.
Save rowej83/e11007c309ce7bc20d6736992a1b4f8d to your computer and use it in GitHub Desktop.
Example of extending REST API for Wordpress to include a field not normally returned in result
/*
|--------------------------------------------------------------------------
| Prepare REST
|--------------------------------------------------------------------------
*/
function prepare_rest($data, $post, $request){
$_data = $data->data;
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$thumbnail300x180 = wp_get_attachment_image_src( $thumbnail_id, '300x180' );
$thumbnailMedium = wp_get_attachment_image_src( $thumbnail_id, 'medium' );
$_data['fi_300x180'] = $thumbnail300x180[0];
$_data['fi_medium'] = $thumbnailMedium[0];
$data->data = $_data;
return $data;
}
add_filter('rest_prepare_post', 'prepare_rest', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment