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




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'])) {

In the main page,I linked the physician link as


but it keep going to the home page.When I tried changed the link as


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!

  • It seems, you did not call/hook the add_rewrite_rules function...? Or did I just overlook that?
    – tfrommen
    Mar 15, 2013 at 15:50
  • Oh, I forgot to paste and copy them. Already added them in the code.
    – Pluto
    Mar 15, 2013 at 15:52

1 Answer 1


The tutorial is outdated and it seems it missed to flush the rules.

function add_rewrite_rule_and_tag() {

    global $wp_rewrite;

    add_rewrite_rule( '^physician-profile/([^/]*)/?', 'physician-profile?lastName=$matches[1]', 'top' );
    add_rewrite_tag( '%lastName%','([^&]+)' );

    if ( ! isset( $wp_rewrite->rules['^physician-profile/([^/]*)/?'] ) )



add_action( 'init', 'add_rewrite_rule_and_tag', 99 );

You can access the query var `lastName´ with

gloabl $wp_query;
$lastName = $wp_query->query_vars['lastName'];
  • Thank you Ralf, but I tried to put codes in the function.php, and then nothing happened. I even used rewrite analyzer but it the new rule didn't show in the analyzer.
    – Pluto
    Mar 18, 2013 at 14:18
  • I figured it out. Thank the link should be index.php?pagename=physician-profile..balabala
    – Pluto
    Mar 18, 2013 at 18:38

Your Answer

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

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