WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 created the page template which needs to take some GET variables, currently URL's looks like that:


I need to make that way:


I checked the WP_Rewrite documentation and playing a bit with that stuff, but can't make things work as except.

Regards, Chris

share|improve this question
up vote 0 down vote accepted

First you have to filter query vars and add your query var to the array:

add_filter( 'query_vars', 'wpa56345_query_vars' );

function wpa56345_query_vars( $query_vars ){
    $query_vars[] = 'cat_id';
    return $query_vars;

Then your rule which captures any digits after your pagename coupons and passes that as cat_id:

add_action( 'init', 'wpa56345_rewrites' );

function wpa56345_rewrites(){

The above both go in your theme's functions.php. Make sure to visit permalinks settings page after adding rewrite rules to flush rules, or they will not take effect. If you put everything into a plugin, you can set it up to flush rules when they are first added.

anyway, in your template, you can then access the value of cat_id with:

echo get_query_var( 'cat_id' );
share|improve this answer

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.