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?


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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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