0

I'm having basically the same problem as question #44117. I have a custom rewrite rule set using add_rewrite_rule, but when the user goes to the page, the entered url changes and the value is lost.

User enters: membership/member-profile/profile-name/

And is forwarded to: membership/member-profile/

Here's my rewrite code:

function profile_rewrite() {
    add_rewrite_rule('membership/member-profile/([^/]+)/?', 'index.php?pagename=member-profile&profile=$matches[1]', 'top');
}
add_action('init', 'profile_rewrite');

I've been researching for hours, and while I've found others with a similar problem, there has never been a definite solution.

Maybe it's a problem with my Wordpress settings? If I enter the URL:

index.php?pagename=member-profile&profile=test

I'm forwarded to:

membership/member-profile/?pagename=member-profile&profile=test

Which returns a 404 error.

Thanks in advance for any help. I'm pretty new to this Wordpress stuff and maybe I'm jumping in a bit too quickly.

2

this:

add_rewrite_rule(
    'membership/member-profile/([^/]+)/?$',
    'index.php?pagename=member-profile&profile=$matches[1]',
    'top' );

should be:

add_rewrite_rule(
    'membership/member-profile/([^/]+)/?$',
    'index.php?pagename=membership/member-profile&profile=$matches[1]',
    'top' );

the difference is pagename should contain the parent/child path.

also- if profile isn't a recognized query var, it needs to be added in order to be accessed:

function wpse47596_query_vars( $query_vars ){
    $query_vars[] = 'profile';
    return $query_vars;
}
add_filter( 'query_vars', 'wpse47596_query_vars' );
  • Thank you so much! Adding the parent fixed my problem and the value is even showing up. – Steven Apr 1 '12 at 20:08

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.