I'm trying to create my own permalinks with wordpress rewrite API. I have been registering my get variables as it follows

add_filter( 'query_vars','driver_vars' );
function driver_vars( $vars ) {
    global $wp_query;
    array_push($vars, 'cat_name');
    array_push($vars, 'group');
    return $vars;

and making my own rule as it follows

function drivers_rewrite_rules( $rules ) {
    global $wp_rewrite;
    $newrules = array(
                        'drivers/([^/]+)/([^/]+)/([^/]+)/?$' =>   'index.php?pagename=drivers&cat_name=$matches[1]&group=$matches[2]&product=$matches[3]'
    $finalrules = $newrules + $rules;

    return $finalrules;

my rewrite rule is not getting executed on the second and third variable when I var_dump($wp_query->query_vars) I see just my cat_name variable.

if I access with the following url structure than it's okay

  • Have you used $wp_rewrite->flush_rules(); ? – m4t1t0 Nov 1 '12 at 10:03
  • No I haven't use it. I'm quite newbie in plugin development. On my firs variable seems to work if I use /drivers/Desktop the variable is getting fired. On /drivers/Desktop/Alienware second I'm getting 404 – kakuki Nov 1 '12 at 10:07
  • okay fix it for each variable I've been adding a structure in the array and it works but I don't know if this one is the best workaround – kakuki Nov 1 '12 at 12:56

Your Answer

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

Browse other questions tagged or ask your own question.