WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
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
up vote 5 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
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

Your Answer


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.