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

1 Answer 1


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' );

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.