Skip to content

Instantly share code, notes, and snippets.

@gopperman
Created July 19, 2017 03:41
Show Gist options
  • Save gopperman/801c3d55e38bae6a28f3ecfcfb6b8d60 to your computer and use it in GitHub Desktop.
Save gopperman/801c3d55e38bae6a28f3ecfcfb6b8d60 to your computer and use it in GitHub Desktop.
Add a custom meta field to wordpress API response
function my_rest_prepare_post( $data, $post, $request ) {
$_data = $data->data;
$_data['URL'] = get_post_meta( $post->ID, 'URL', true );
$data->data = $_data;
return $data;
}
add_filter( 'rest_prepare_post', 'my_rest_prepare_post', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment