I'm creating a plugin that handles courses from a 3rd party system, I've created a add_rewrite_rule() so the url /course/32567 rewrites to /wp-content/plugins/course-plugin/course-page.php?code=32567

but the code= section doesn't get passed even though i've created a add_rewrite_tag()

add_action( 'init', function(){

add_rewrite_tag( '%code%', '[^a-zA-Z0-9_/]' );


} );

and in the course-page.php file

<h1>COURSE: <?php echo $wp_query->query_vars['code']; ?></h1>

But it's displaying $wp_query->query_vars['code'] as $matches[1]

Any ideas? Thanks

  • Did you flush the rewrite rules? Commented Oct 9, 2014 at 3:15
  • Yep made sure i flushed them manually too
    – Jason
    Commented Oct 9, 2014 at 8:45

1 Answer 1


You can always check the value of the result with the function var_dump as follows:

var_dump( $matches[1] );

In this case, I think is returning an Array with the results you should try to out.

<?php echo $matches[1][0] ; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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