Skip Navigation

[Resolved] Default layout for recurring events created by Events Manager

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to set Default layout for recurring events created by Events Manager

Solution:
Toolset offers a filter "get_layout_id_for_render" that you can use to force the layout you want to display while displaying your posts.

you can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/default-layout-for-recurring-events-created-by-events-manager/#post-956362

Relevant Documentation:

This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 3 voices.

Last updated by Nigel 6 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#955717

I am using hidden link on two sites - one just launched, one in development.

My issue is with recurring events.

The recurring event has its own post type, "event-recurring". After creating a recurring event, it generates individual events, post type "event", which are actually displayed on the site.

I can associate a Layout with an "event" without a problem when creating a (non-recurring) Event directly. But when I create a recurring event (or edit an existing recurring event) the subsequent events that are created/updated do not have the Layout assigned.

Is there some way that I can force the Layout assignment for these event posts that are generated from a event-recurring post?

If I can provide more information to make this more clear please let me know. Thanks as always for your help.

#956362

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - Toolset offers a filter get_layout_id_for_render that you can use to force the layout you want to display while displaying your posts.

For example - please add following code to your current theme's functions.php file:

add_filter('get_layout_id_for_render', function($id, $slug){
          
        global $post;
   
        if( null !== $post && $post->post_type === 'post-type-slug'){
            $id = 9999;
        }
        return $id;
} );

Where:
- Replace 'post-type-slug' with your required post type slug
- Replace 9999 with the required layout ID you want to render with that post type posts

I hope above solution will help you to resolve your issue.

#956381

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

If the Events Manager plugin is programmatically generating the event posts it seems like the hook used by Layouts to assign the template is being missed.

I haven't looked at the Events Manager code but I assume they will be creating the event posts using standard WP functions, e.g. save_post.

In which case it should be possible to use the save_post_event hook that is triggered whenever an event post is saved or updated to set the Template Layout, which is stored as post_meta with a key of _layouts_template.

So you could add the following code to your site (editing the slug of the required layout):

add_action( 'save_post_event', 'tssupp_set_event_template' );
function tssupp_set_event_template( $post_id ){

	$template_slug = 'single-event'; // Edit

	update_post_meta( $post_id, '_layouts_template', $template_slug );
}

That is fairly crude, it doesn't allow you to assign different templates to different events, all events will have that template assigned.