Skip to content

Instantly share code, notes, and snippets.

@jeffcdavis
Created December 3, 2014 16:16
Show Gist options
  • Save jeffcdavis/31a907399e34827a4248 to your computer and use it in GitHub Desktop.
Save jeffcdavis/31a907399e34827a4248 to your computer and use it in GitHub Desktop.
Add meta data to WP-API custom post type without authorization (example here is for Tribe Events Calendar)
<?php
add_filter( 'json_prepare_post', function ($data, $post, $context) {
$data['myextradata'] = array(
'start_date' => get_post_meta( $post['ID'], '_EventStartDate', true ),
'end_date' => get_post_meta( $post['ID'], '_EventEndDate', true ),
);
return $data;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment