Embedding custom posts with REST API
I am trying to find a way to embed basing custom post infomation, such as post title and few custom metas on other website.
The easiest seems to be doing it in iFrame, but there are many "no's", you can't style it as much as you want etc. So after update to 4.7 and avaiability of REST API I though it would be great to use that, and retrievve needed values with API call. But when I try to use https://example.com/wp-json/wp/v2/posts/11
where 11
is custom post type called st_activity
, I'm getting post content and all the information but my custom meta is missing.
I've registered custom post type with API support, following
adding
'show_in_rest' = true,
'rest_base' = 'activity-api',
'rest_controller_class' = 'WP_REST_Posts_Controller',
and adjusted meta:
function slug_register_rate_review() {
register_rest_field( 'st_activity',
'rate_review',
array(
'get_callback' = 'slug_get_st_activity',
'update_callback' = null,
'schema' = null,
)
);
}
function slug_get_st_activity($post, $field_name, $request) {
return get_post_meta($post['id'], 'rate_review' );
}
Well, obviously I'm doing something wrong but have no idea what exactly.
And ddespite that, is it possible and how to get only title, link, and custom meta without all the other values? Thank you!