Answers.Body: <p>My solution for this issue was to use the filter <code>page_link</code>, called (indirectly) by <code>get_permalink</code> function. This way, the URL used on form <code>action</code> attribute is correct.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-15T14:05:20.597Z
Answers.LastActivityDate: 2023-11-15T14:05:20.597Z
Answers.UserDisplayName: marcelo2605
Answers.Body: <p>I would suggest using CiviCRM <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/" rel="nofollow noreferrer">buildForm</a> or <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess/" rel="nofollow noreferrer">preProcess</a> hook to alter the event registration pages</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-14T16:05:37.843Z
Answers.Text: 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.
Answers.UserDisplayName: marcelo2605
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-14T16:32:28.393Z
Answers.Text: 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');
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-14T17:42:15.063Z
Answers.Text: 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.
Answers.UserDisplayName: marcelo2605
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-14T15:57:57.937Z
Answers.LastActivityDate: 2023-11-14T15:57:57.937Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I have a page called event and set the bellow rewrite rule to store the event ID in the URL:</p>
  <pre><code>add_action('init', function () {
      add_rewrite_rule(
          '^event/(\d+)/?$',
          'index.php?pagename=event&amp;event_id=$matches[1]',
          'top'
      );
  });
  
  add_filter('query_vars', function ($vars) {
      $vars[] = 'event_id';
      return $vars;
  });
  </code></pre>
  <p>e.g. mysite.com/event/37/</p>
  <p>Works fine until user clicks on Review button and CiviCRM removes the id from URL:</p>
  <p>e.g. mysite.com/event/?civiwp=CiviCRM&amp;q=civicrm%2Fevent%2Fregister&amp;_qf_Register_display=true&amp;qfKey=CRMEventControllerRegistration...</p>
  <p>Is there a way to keep the ID or get the event ID using other solution?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-14T15:18:39.800Z
Comments.Text: Depends upon how you using it. Are you using Civi hooks or wp hooks?
Comments.UserDisplayName: Pradeep Nayak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-14T15:20:57.770Z
Comments.Text: @PradeepNayak You mean to render the event form? I'm using shortcode and set the Shortcode Display Mode to "Remain in Shortcode Mode".
Comments.UserDisplayName: marcelo2605
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-14T15:46:02.117Z
Comments.Text: any reason you want to retain the id? What you trying to achieve by adding id in the URL?
Comments.UserDisplayName: Pradeep Nayak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-14T15:49:13.057Z
Comments.Text: @PradeepNayak the layout of the event page is very customized. I need the event ID to get things like the event title.
Comments.UserDisplayName: marcelo2605
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-14T15:56:18.120Z
Comments.Text: Have you tried civicrm hooks to alter the pages? like buildForm or preProcess
Comments.UserDisplayName: Pradeep Nayak
Tags: <wordpress><civievent>
Title: Custom event page not keep event ID when click on Review button
ThreadText: # Custom event page not keep event ID when click on Review button
  
  (Asked by: username_0 on 2023-11-14)
  
  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?
  
  **Tags:** wordpress, civievent
  
  > **Comments:**
  > **username_1**: Depends upon how you using it. Are you using Civi hooks or wp hooks?  
  > **username_0**: @username_1 You mean to render the event form? I'm using shortcode and set the Shortcode Display Mode to "Remain in Shortcode Mode".  
  > **username_1**: any reason you want to retain the id? What you trying to achieve by adding id in the URL?  
  > **username_0**: @username_1 the layout of the event page is very customized. I need the event ID to get things like the event title.  
  > **username_1**: Have you tried civicrm hooks to alter the pages? like buildForm or preProcess  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2023-11-15. Score: 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.
  
  
  ---
  
  ### Answer by username_1 on 2023-11-14. Score: 1
  
  I would suggest using CiviCRM [buildForm](https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/) or [preProcess](https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess/) hook to alter the event registration pages
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_1**: 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');  
  > **username_0**: 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.  
  
  ---
  
  