//Add in functions.php,this hook is for my 'doctor' post type
add_action('rest_api_init','create_api_posts_meta_field');
function create_api_posts_meta_field(){
register_rest_field('doctor','group',array(
'get_callback' =>'get_post_meta_for_api',
'schema' => null,
));
}
//Use the post ID to query the image and add it to your payload
function get_post_meta_for_api($object){
$post_id = $object['id'];
$post_meta = get_post_meta($post_id);
$post_image = get_post_thumbnail_id($post_id);
$post_meta["group_image"] = wp_get_attachment_image_src($post_image)[0];
return $post_meta;
}
//Add in functions.php,this hook is for my 'doctor' post type
add_action('rest_api_init','create_api_posts_meta_field');
function create_api_posts_meta_field(){
register_rest_field('doctor','group',array(
'get_callback' =>'get_post_meta_for_api',
'schema' => null,
));
}
//Use the post ID to query the image and add it to your payload
function get_post_meta_for_api($object){
$post_id = $object['id'];
$post_meta = get_post_meta($post_id);
$post_image = get_post_thumbnail_id($post_id);
$post_meta["group_image"] = wp_get_attachment_image_src($post_image)[0];
return $post_meta;
}