Skip to content

Instantly share code, notes, and snippets.

@arippberger
Created July 23, 2014 19:32
Show Gist options
  • Save arippberger/8514af9475b64442996a to your computer and use it in GitHub Desktop.
Save arippberger/8514af9475b64442996a to your computer and use it in GitHub Desktop.
Get public meta values in WP-API
function my_prepare_post( $post_response, $post, $context ) {
$meta = get_post_custom( $post['ID'] );
$custom_fields = array();
foreach ( $meta as $key => $value ) {
if ( '_' !== substr( $key, 0, 1 ) ) {
$custom_fields[ $key ] = $value;
}
}
$post_response['custom_fields'] = $custom_fields;
return $post_response;
}
add_filter( 'json_prepare_post', 'my_prepare_post', 10, 3 );
@arippberger
Copy link
Author

this code in your plugin would add any custom field not starting with "_" to the response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment