Skip to content

Instantly share code, notes, and snippets.

@joedajigalo
Last active August 29, 2015 14:07
Show Gist options
  • Save joedajigalo/20b362622da164b861ca to your computer and use it in GitHub Desktop.
Save joedajigalo/20b362622da164b861ca to your computer and use it in GitHub Desktop.
Display custom post metadata that start with universal prefix
// --- 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