Last active
August 29, 2015 14:07
-
-
Save joedajigalo/20b362622da164b861ca to your computer and use it in GitHub Desktop.
Display custom post metadata that start with universal prefix
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
// --- WP-API | Display all custom post metadata that start with 'xxx_' --- // | |
function wmi_past_poss_custom_metadata( $post_response, $post, $context ) { | |
$meta = get_post_custom( $post['ID'] ); | |
$custom_fields = array(); | |
foreach ( $meta as $key => $value ) { | |
// Replace 'xxx_' with any custom metakey prefix (ie. '_' for private metakey's) | |
if ( 'xxx_' !== substr( $key, 0, 1 ) ) { | |
$custom_fields[ $key ] = $value; | |
} | |
} | |
$post_response['custom_fields'] = $custom_fields; | |
return $post_response; | |
} | |
add_filter( 'json_prepare_post', 'wmi_past_poss_custom_metadata', 10, 3 ); | |
// --- Complements of https://github.com/WP-API/WP-API/issues/367 --- This was lost, now it's found ;)// | |
// --- END WP-API | Display all custom post metadata that start with 'xxx_' --- // |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment