I'm using an events calendar plugin to list events on my WordPress site. It uses a custom post type to give each event its own page. There are one-off events and recurring events (eg an event that runs every Friday).

The event pages have dynamic URLs, which is not so good for things like Google event listings. I'd like to change them to pretty URLs.

The original URL for each event looks like this:


The 'instance_id' is what differentiates multiple instances of a recurring event.

I want to change the URL to:


So all I'm looking to do is remove "?instance_id=" from the URL.

I'm struggling with rewrite rules and Regex! I added the following function to my functions.php file.

// Rewrite event page URLs
function rewrite_event_urls() {
  if ( is_singular( 'ai1ec_event' ) ) {
    add_rewrite_rule('^event/([^/]*)/([0-9]+)/?', 'index.php?name=$matches[1]&instance_id=$matches[2]', 'top');
add_action('init', 'rewrite_event_urls');

I flushed rewrite rules manually on Settings > Permalinks but my URLs haven't changed.

Can anyone suggest what I'm doing wrong? I'd be so grateful for any help!

Thanks, Chris

  • have you tried to access to URL mydomain.com/event/event-name/123 ? – Kaperto Dec 29 '19 at 10:08
  • Hi there. Yes, I have. It returns the first 'instance' of my recurring event - the event page with the date the event first ran. That's the same behaviour I see if I delete the query string or change it to something that doesn't match an instance ID that exists in the database. So mydomain.com/event/event-name/, mydomain.com/event/event-name/?instance_id=foo and mydomain.com/event/event-name/123 all show the original event page with the original date, not the version for instance_id 123. Does that make sense? – user180331 Dec 30 '19 at 12:01
  • The same applies if I delete the URL rewrite function from my functions file. – user180331 Dec 30 '19 at 12:01
  • look this to read the argument of the instance : wordpress.stackexchange.com/questions/352189/… – Kaperto Dec 30 '19 at 12:17
  • Hi. Thanks again. I tried that but still no luck. :( – user180331 Jan 5 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.