• mannyotr

    (@mannyotr)


    Right now I have three pages that I am passing parameters into.

    I am using the code below in my child theme ‘functions.php’ in order to set everything up correctly.

    function add_query_vars($aVars) {
      $aVars[] = "profile_status";
      $aVars[] = "raceid";
      $aVars[] = "category";
    return $aVars;
    }
    
    add_filter('query_vars', 'add_query_vars');
    
    function add_rewrite_rules($aRules) {
    
      $aNewRules = array(
                         'racer-profile/([^/]+)/?$'             => 'index.php?pagename=racer-profile&profile_status=$matches[1]'
                        ,'race-registration-page2/([^/]+)/?$'   => 'index.php?pagename=race-registration-page2&raceid=$matches[1]'
                        ,'race-registration-page3/([^/]+)/?$'   => 'index.php?pagename=race-registration-page3&raceid=$matches[1]&category=$matches[2]'
                        );
    
      $aRules = $aNewRules + $aRules;
    
    return $aRules;
    }
    
    add_filter('rewrite_rules_array', 'add_rewrite_rules');

    Using that code I am able to call one of the pages like this, where ‘8’ is the ‘raceid’ parameter value:

    https://mydomain.com/race-registration-page2/8/

    That works just fine.

    But as you can see in my code, for one of my pages (race-registration-page3) I am trying to pass two parameters (‘raceid’ and ‘category’).

    When I call that page with just one parameter (‘raceid’) it works perfectly. But as soon as I call it with two parameters (see below), it doesn’t work.

    https://mydomain.com/race-registration-page3/8/Solo/

    What am I doing wrong?

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter mannyotr

    (@mannyotr)

    I figured it out. I needed to fix one small detail…

    'racer-profile/([^/]*)/?'                   => 'index.php?pagename=racer-profile&profile_status=$matches[1]'
    ,'race-registration-page2/([^/]*)/?'         => 'index.php?pagename=race-registration-page2&raceid=$matches[1]'
    ,'race-registration-page3/([^/]*)/([^/]*)/?' => 'index.php?pagename=race-registration-page3&raceid=$matches[1]&category=$matches[2]'
Viewing 1 replies (of 1 total)
  • The topic ‘Passing Parameters’ is closed to new replies.