Created
July 23, 2014 19:32
-
-
Save arippberger/8514af9475b64442996a to your computer and use it in GitHub Desktop.
Get public meta values in WP-API
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
| 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this code in your plugin would add any custom field not starting with "_" to the response