Hi ixodie
you need to have activated the add-on The Options Page :
https://www.advancedcustomfields.com/add-ons/options-page/
Thanks
Thread Starter
ixodie
(@ixodie)
OK, I’m a lot more confused now. The Options Page has totally different functionality than I am looking for. I went ahead and bought a license to test it but I have no idea why I would have to use that to enable the ACF REST endpoint.
Can you explain this a bit further?
Hi ixodie,
The endpoint /wp-json/acf/v2/options works only with the plugin “The options page”.
If you have book as CPT, the endpoint is:
/wp-json/acf/v2/book/{id}
/wp-json/acf/v2/{custom-post-type}/{id}
Endpoints available:
https://github.com/airesvsg/acf-to-rest-api#endpoints
Thanks
Thread Starter
ixodie
(@ixodie)
OK.
So is there a way to retrieve all id’s from cpt from this endpoint or do we need to do:
https://www.www.com/wp-json/wp/v2/custom-post-type?filter%5Bposts_per_page%5D=-1
Which painfully returns a ton of unneeded bits of data.
Thread Starter
ixodie
(@ixodie)
Also can we include featured_image as a returned field in an easy way?
In my plugin isn’t possible yet. You must have use the url below.
https://www.www.com/wp-json/wp/v2/custom-post-type?
filter[posts_per_page]=-1
Code to append featured image url:
add_filter( 'rest_prepare_post', 'rest_fatured_image', 20, 3 );
function rest_fatured_image( $response, $post, $request ) {
$data = array();
if ( $response instanceof WP_REST_Response ) {
$data = $response->get_data();
} else {
return $response;
}
if ( isset( $data['featured_media'] ) && $data['featured_media'] ) {
$data['featured_media_url'] = wp_get_attachment_url( $data['featured_media'] );
}
return $data;
}
Thanks