I have already followed the tutorial here: http://www.rlmseo.com/blog/passing-get-query-string-parameters-in-wordpress-url/
But it still doesn’t work.
In the function.php, my code is
//decode wordpress url to jquery string
function add_query_vars($aVars) {
$aVars[] = "lastName";
return $aVars;
}
// hook add_query_vars function into query_vars
add_filter('query_vars', 'add_query_vars');
function add_rewrite_rules($aRules) {
$aNewRules = array('^physician-profile/([^/]*)/?' => 'physician-profile?lastName=$matches[1]');
$aRules = $aNewRules + $aRules;
return $aRules;
}
// hook add_rewrite_rules function into rewrite_rules_array
add_filter('rewrite_rules_array', 'add_rewrite_rules');
I would like my link from
physician-profile?lastName=Rae-Lee
to
physician-profile/Rae-Lee.
In the pysician-profile page, my code is: but I don’t know why I put it here. It seems like just return the value of lastName.
if(isset($wp_query->query_vars['lastName'])) {
$lastNameS=(urldecode($wp_query->query_vars['lastName']));
In the main page,I linked the physician link as
physician-profile/Rae-Lee,
but it keep going to the home page.When I tried changed the link as
physician-profile?lastName=Rae-Lee,
it goes directly that page, but the URL doesn’t change.
As a wordpress beginner, could you point it out which part I did wrong?
Or do I need other codes?
Thank you for your help!
The tutorial is outdated and it seems it missed to flush the rules.
You can access the query var `lastName´ with