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

I have a custom page and template, that I'm passing a query-string to. It has a wordpress permalink like so


I want to be able to add another rule so that the permalink receives a slug


is rewrote to


share|improve this question
up vote 3 down vote accepted

This should work for you-

function wpse28906_rewrites_init(){
        'top' );
add_action( 'init', 'wpse28906_rewrites_init' );

function wpse28906_query_vars( $query_vars ){
    $query_vars[] = 'myslug';
    return $query_vars;
add_filter( 'query_vars', 'wpse28906_query_vars' );

You can then use get_query_var( 'myslug' ) in your template to get your slug value. Don't forget to flush your rewrite rules after adding this by visiting the permalinks settings page.

share|improve this answer
how do i flush the rewrite rules? I visited the page and hit save. I cant access get_query_var( 'myslug' ). – madphp Sep 19 '11 at 18:04
@madphp - just visiting the permalinks settings page flushes them. echo get_query_var( 'myslug' ) should echo the value of myslug if it's set. if you visit /mypage/anything/ and don't get a 404 or redirected, then the rewrite rule is working. – Milo Sep 19 '11 at 18:22
do I need to use add_rewrite_tag somewhere? codex.wordpress.org/Rewrite_API/add_rewrite_tag . I dont get a 404, by going to /mypage/anything/ but i cant access the myslug query_var. – madphp Sep 19 '11 at 18:23
Im using WordPress 3.0.4 – madphp Sep 19 '11 at 18:40
I can access query variable like this. $wp->query_vars['myslug']; Is that acceptable? – madphp Sep 19 '11 at 18:48

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.