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.
function my_add_rewrite_rules() {

  add_rewrite_rule('testing/([^/]+)?$', 'index.php?pagename=testing&event_slug=$matches[1]', 'top' ); 

}
add_action( 'init', 'my_add_rewrite_rules' );

function add_query_vars( $query_vars ) {
  $query_vars[] = 'event_slug';
  return $query_vars;
}
add_filter( 'query_vars', 'add_query_vars' );   

/testing/foo - Works, shows foo

If I have testing set to no parent, the rewrite works and everything is good to go.

If I set testing to a child of, lets say about, and update the add_rewrite_rule to..

add_rewrite_rule('about/testing/([^/]+)?$', 'index.php?pagename=testing&event_slug=$matches[1]', 'top' ); 

... it loads about/testing but strips out my custom query_var and displays the page normally.

/about/testing/foo - Loads page, doesn't show foo

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

if it's a child page, you have to update pagename to reflect the parent/child path:

add_rewrite_rule('about/testing/([^/]+)?$', 'index.php?pagename=about/testing&event_slug=$matches[1]', 'top' );
share|improve this answer
1  
Well, I feel stupid now. Thanks! –  Matt Vickers May 1 '12 at 18:56
    
Perfect! That works for me! –  James Jun 12 '13 at 19:39
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.