Custom Permalink Structure for The Events Calendar


I am trying, programmatically, to alter the permalink structure of events created by The Events Calendar plugin. I already have other posts and pages set-up and don’t want to change the permalink settings.

So the plugin currently creates events with structure:

The current site (non-WordPress) currently uses:

I would like to keep that structure. I have code that creates a permalink, or at least partly:

function my_custom_rewrite() {
    global $wp_rewrite;
    $wp_rewrite->add_permastruct('tribe_events', '/events/%year%/%name%/', false);
add_action('init', 'my_custom_rewrite');

function my_custom_permalinks( $permalink, $post ) {
    if  ($post->post_type == 'tribe_events') {

        $meta = get_post_meta($post->ID);
        $newDate = date("Y", strtotime( $meta['_EventStartDate'][0] ));
        return str_replace( array('%year%','%name%'), array($newDate,$post->post_name), $permalink );
  return $permalink;
add_filter( 'post_type_link', 'my_custom_permalinks', 10, 2 );

I know it is not perfect. now redirects to Perfect but shows 404. I have tried a number of hooks, pre_post, etc… but can’t seem to get WordPress to show the event on the new URL. Can anyone point me to the correct hooks to use to finish this/get it working?


, nickbits 3 years 2019-10-31T05:51:56-05:00 0 Answers 82 views 0

Leave an answer