Support

Home Forums Event Espresso Premium REST API base slug

REST API base slug

Posted: December 22, 2020 at 5:08 am

Viewing 6 reply threads


stefan@netdust.be

December 22, 2020 at 5:08 am

Hi

In order for event espresso to work with my theme I need to set the REST API base slug rest_base set to the plural version of the post type key. I try like this, but it doesn’t work… any idea what the rest_base slug should be?

add_filter( 'register_post_type_args', 'my_post_type_args', 10, 2 );

function my_post_type_args( $args, $post_type ) {

    if ( 'espresso_events' === $post_type ) {
        $args['show_in_rest'] = true;

        // Optionally customize the rest_base or rest_controller_class
        $args['rest_base']             = 'espresso_events';
        $args['rest_controller_class'] = 'WP_REST_Posts_Controller';
    }

    return $args;
}


Tony

  • Support Staff

December 23, 2020 at 4:50 am

Hi there,

May I ask why your theme needs this to be changed?

rest_base defaults to the value of post_type, so this:

$args['rest_base'] = 'espresso_events';

Is the default for the espresso_events post type anyway.

$args['rest_controller_class'] = 'WP_REST_Posts_Controller';

Is the default for that value, meaning for the snippet above both of those can be remove leaving just:

$args['show_in_rest'] = true;

However, looking at your site with the above snippet this EE event posts should show on {domain}/wp-json/wp/v2/espresso_events but on your site they do not, which means that code likely isn’t running currently.

Have you disabled the above? If not, where do you have it saved currently?


stefan@netdust.be

December 23, 2020 at 5:20 am

Hi

I used that code to change the rest_base to singular
https://staging.neerhof-boerderij.be/wp-json/wp/v2/espresso_event

The issue is that as soon as I set the rest_base like this, I get an error in my themebuilder…
It only happens when I try this with the event espresso custom post types, not with a test posttype (members ) I created in the same install…

thx
Stefan


Tony

  • Support Staff

December 23, 2020 at 5:38 am

I used that code to change the rest_base to singular

In your opening post, you set it to the plural, but here you are using the singular?

The issue is that as soon as I set the rest_base like this, I get an error in my themebuilder…

Why are you setting EE’s posts to use the singular?

Which theme?


stefan@netdust.be

December 23, 2020 at 5:45 am

I know, i just set it to singular to check if that piece of code works, it does. plus, I have no idea what the plural of ‘espresso_events’ is, it’s allready plural. sorry for the confusion here.

I am using yootheme builder for my theme and i requires that the rest_base is set to plural from the posttype key. in this case the key is ‘espresso_events’.
If I don’t set the rest_base, the posttype doesn’t show in the builder and as soon as I try to change it to something ( doesn’t matter what I type ), the builder gives an error.

As I mentioned, this doesn’t happen with other posttypes. If i set the rest_base of posttype ‘member’ to ‘members’ with that same piece of code. The posttype shows up in the builder


Tony

  • Support Staff

December 23, 2020 at 7:15 am

In short, Event Espresso doesn’t currently support page builders and by the looks of it, YooTheme Builder doesn’t support EE events.

I checked their documentation for this here:

https://yootheme.com/support/yootheme-pro/wordpress/dynamic-content#custom-post-types

So I now understand a little more of what you are trying to do, but as you mentioned, the post type key for EE events is plural already with espresso_events and I have no idea what logic would be applied to that, espresso_eventses?

In any case, I think even if you managed to get to EE posts to loaded within the builder you still wouldn’t have full control over the output as EE injects the event details into the_contet() of espresso_events posts, you won’t be able to control that with a page builder.


stefan@netdust.be

December 23, 2020 at 7:19 am

ok,… I knew it was a long shot 🙂
thx for your time and looking into it! as always there are workarounds.

Viewing 6 reply threads

The support post ‘REST API base slug’ 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.

Event Espresso