Thankfully, author has added a good number of hooks in order to allow customization of action, extension and results. I found that I was unable to retrieve a num post count when querying a post type. Because I plan to interface with a mobile app, I want to allow for them to correctly display pagination. In order to do that, they will need to know either how many pages can be made regulated by posts per or how many posts total so they can calculate it themselves. I hooked into post type data to add that information to the result array:
function send_num_pages_too($data, $type){
$added = array();
//"publish"]=> string(4) "8417" ["future"]=> int(0) ["draft"]=> int(0) ["pending"]=> int(0) ["private"]=> int(0) ["trash"]=> int(0) ["auto-draft"]=> int(0) ["inherit"]=> int(0)
$pcount = wp_count_posts($data['slug'], 'readable');
$added['num_posts'] = (int)$pcount->publish;
$added['num_private_posts'] = (int)$pcount->private;
return array_merge($data, $added);
}
add_filter( 'json_post_type_data', 'send_num_pages_too', 10, 2);
In your guys’ situations, author indicates that with json_prepare_post hook, you can customize the output of your query. He also states that if you pass the param context=post you get all the meta. Here’s the code so you can see that you are getting that (the $post_fields_raw[‘post_meta’] returns almost all meta. if you have not requested raw data, you will not get back serialized values, otherwise, you will)
if ( 'edit' === $context ) {
if ( current_user_can( $post_type->cap->edit_post, $post['ID'] ) ) {
if ( is_wp_error( $post_fields_raw['post_meta'] ) ) {
return $post_fields_raw['post_meta'];
}
$_post = array_merge( $_post, $post_fields_raw );
} else {
return new WP_Error( 'json_cannot_edit', __( 'Sorry, you cannot edit this post' ), array( 'status' => 403 ) );
}
}
Or if you hook into the json prepare post filter, you can do something like this:
function playWithMeta($postray, $postdat, $context){
$morestuff = get_post_meta($postdat['ID']);
//don't do this, you will probably be duplicating a bunch of stuff
return array_merge($postray, $morestuff);
}
add_filter( 'json_prepare_post', 'playWithMeta',10, 3 );