I have this code in my wordpress plugin. I'm working on an vue powered headless theme and I need to get all the informations about pages using the rest API.
I've registered with success a custom res field for a cpt, but now when I try to add a rest field for page object, it will be not added if I call the wp-json\wp\v2\pages
I will not see the added field
function __construct()
{
add_action('rest_api_init', [$this, 'setup_custom_routes']);
}
function setup_custom_routes(){
register_rest_field(
'page',
'page_cover',
[
'get_callback' => [$this, 'get_pages_cover']
]
);
}
function get_pages_cover( $post ){
return get_the_post_thumbnail_url( $post['id'] );
}
Is there something wrong, or I need to do this in another way?
setup_custom routes
?page_cover
is not in the response JSON, or was it there, but empty (no value)? How did you confirm the field was not there, how do you "callwp-json/wp/v2/pages
"?