2016-01-18 2 views
0

Я пытаюсь получить параметры страницы без редактирования .htaccess в WordPress как это:WordPress - Создание дополнительных параметров факультативные

От: http://localhost/wordpress1/download/?image=64&resolution=1024x768&nonce=a102d152a0

к: http://localhost/wordpress1/download/64/1024x768/a102d152a0/

Мой код ниже, не работает и приводит к ошибке 404.

function new_rewrite_rule(){ 
    add_rewrite_rule(
     'download/([0-9]+)/([a-z]+)/([a-z]+)/?$', 
     'index.php?pagename=download&image=$matches[1]&resolution=$matches[2]&nonce=$matches[3]', 
     'top' 
    ); 
} 
add_action('init', 'new_rewrite_rule'); 

function new_query_vars($query_vars) { 
    $query_vars[] = 'image'; 
    $query_vars[] = 'resolution'; 
    $query_vars[] = 'nonce'; 

    return $query_vars; 
} 
add_filter('query_vars', 'new_query_vars'); 

ответ

0

решена мною, Финальный код

function new_rewrite_rule(){ 
    global $wp_rewrite; 
    $wp_rewrite->flush_rules(); 

    add_rewrite_rule(
     'download/([0-9]+)/([a-zA-z0-9]+)/([a-zA-z0-9]+)/?$', 
     'index.php?pagename=download&image=$matches[1]&resolution=$matches[2]&nonce=$matches[3]', 
     'top' 
    ); 
} 

add_action('init', 'new_rewrite_rule'); 

function new_query_vars($query_vars) { 
    $query_vars[] = 'image'; 
    $query_vars[] = 'resolution'; 
    $query_vars[] = 'nonce'; 

    return $query_vars; 
} 
add_filter('query_vars', 'new_query_vars'); 
Смежные вопросы