0

I have a page called event and set the bellow rewrite rule to store the event ID in the URL:

add_action('init', function () {
    add_rewrite_rule(
        '^event/(\d+)/?$',
        'index.php?pagename=event&event_id=$matches[1]',
        'top'
    );
});

add_filter('query_vars', function ($vars) {
    $vars[] = 'event_id';
    return $vars;
});

e.g. mysite.com/event/37/

Works fine until user clicks on Review button and CiviCRM removes the id from URL:

e.g. mysite.com/event/?civiwp=CiviCRM&q=civicrm%2Fevent%2Fregister&_qf_Register_display=true&qfKey=CRMEventControllerRegistration...

Is there a way to keep the ID or get the event ID using other solution?

5
  • Depends upon how you using it. Are you using Civi hooks or wp hooks? Commented Nov 14, 2023 at 15:18
  • @PradeepNayak You mean to render the event form? I'm using shortcode and set the Shortcode Display Mode to "Remain in Shortcode Mode". Commented Nov 14, 2023 at 15:20
  • any reason you want to retain the id? What you trying to achieve by adding id in the URL? Commented Nov 14, 2023 at 15:46
  • @PradeepNayak the layout of the event page is very customized. I need the event ID to get things like the event title. Commented Nov 14, 2023 at 15:49
  • Have you tried civicrm hooks to alter the pages? like buildForm or preProcess Commented Nov 14, 2023 at 15:56

2 Answers 2

1

I would suggest using CiviCRM buildForm or preProcess hook to alter the event registration pages

3
  • I'm using civicrm_buildForm to add a hidden field with the event id and I'm able to get this value using $_POST when user click on Review button. However, I'm not able to do the same when user click on Go Back button. Commented Nov 14, 2023 at 16:05
  • you can use $form->getVar('_id'); to get the event id, if you want to store that id somewhere so that you can access it in any function you can use Civi::$statics['myCustomPluginName']['eventId'] = $form->getVar('_id'); Commented Nov 14, 2023 at 16:32
  • I'm using civicrm_buildForm to store the event form ID, but it seems like the trigger fires too late and I can't use it inside a WordPress template. Commented Nov 14, 2023 at 17:42
1

My solution for this issue was to use the filter page_link, called (indirectly) by get_permalink function. This way, the URL used on form action attribute is correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.