Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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' );
share|improve this answer
    
Thank you so much! Adding the parent fixed my problem and the value is even showing up. –  Steven Apr 1 '12 at 20:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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