I am unable to figure out how to use the REST API to add featured_media to an espresso_events post type.
I tried the wp endpoint using espresso_events as the custom post type (this is how it should work if espresso_events is a CPT):
PUT https://www.theartstudiony.com/wp-json/wp/v2/espresso_events/14566
JSON payload:
{
"featured_media": "2620"
}
I get this:
{
"message": "No route was found matching the URL and request method",
"code": "rest_no_route",
"data": {
"status": 404
}
}
I also tried sending the featured_media param to the ee events REST API but that didn’t work – unsupported.
"message": "You have provided an invalid parameter: "featured_media"",
Is it possible to set a featured image on an event_espresso event using the REST API? If so, would you provide a pointer to code or a sample CURL call I can adapt?
Hmmm… I found this code shortly after posting this request. It allowed the first REST API request to work. I am now able to add a featured image using the featured_media json payload.
However, I wonder if this is the correct way:
/**
* Add REST API support to an already registered post type.
*/
function tasny_post_type_args( $args, $post_type ) {
if ( 'espresso_events' === $post_type ) {
$args['show_in_rest'] = true;
}
return $args;
}
add_filter( 'register_post_type_args', 'tasny_post_type_args', 10, 2 );
There’s nothing wrong with using that method, it sets EE posts types to be available on the standard WP endpoints and as EE events are a custom post type you can use the usual parameters.
Viewing 2 reply threads
The support post ‘Set a featured image using the REST API’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.
Support forum for Event Espresso 3 and Event Espresso 4.