Last active
April 25, 2017 13:53
-
-
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
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
/* | |
|-------------------------------------------------------------------------- | |
| 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