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

Im trying to go from:




Sometimes not all values are set, so it also needs to work with only 2 values set:


The http://www.example.com/product/ page uses its own template file.

This is how my code looks like:

function my_rewrite_rules( $wp_rewrite ) {
    $wp_rewrite->rules =
    array_merge( array(
        '^product/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$' =>
    ), $wp_rewrite->rules);

add_filter( 'generate_rewrite_rules', 'my_rewrite_rules' );

function my_rewrite_queryvars( $qvars ) {
    $qvars[] = 'level1';
    $qvars[] = 'level2';
    $qvars[] = 'level3';
    $qvars[] = 'level4';
    return $qvars;

add_filter( 'query_vars', 'my_rewrite_queryvars' );

It works when im trying to get the query_vars, but it also gives me a 404 page, and not the right template.

What am I doing wrong?

share|improve this question

Okay, I found a solution.

First of all I need to chose the id. Tryed with p=id, but it always returned the page without the parameters. All I needed to do was to add page_id=id instead.

I would also need to add a rewrite for every new level.

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.