Wordpress URL使用随机永久链接重写

时间:2015-02-26 19:32:37

标签: php wordpress

我只是尝试创建wordpress URL基于重写的搜索,但我想在我的域中制作随机slugs,例如:domain.com/rand/query-query而我的默认搜索结果只是domain.com/s/query-query,该怎么做?

global $bb_set;
$bb_set = new stdClass;

$bb_set->url_rewrites = array( 
    '(.+?)' => array('separator' => '-', 'rule' => '(.*)/(.*)', 'index' => 1 ), //this is random
    'search'   => array('separator' => '-', 'rule' => 's/(.*)', 'index' => 1 ), //default
);

function bb_add_rewrite_rules( $wp_rewrite ) {
    global $bb_set;
    $new_rules = array();

    foreach ($bb_set->url_rewrites as $rule) {
        $new_rules[$rule['rule']] =  'index.php?s='.$wp_rewrite->preg_index($rule['index']);
    }
    $wp_rewrite->rules =  $new_rules+$wp_rewrite->rules;
}

function bb_query_vars($public_query_vars){
    $public_query_vars[] = "search";
    return $public_query_vars;
}

function bb_rewrite_rules(){
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

add_filter('query_vars', 'bb_query_vars');
add_action('init', 'bb_rewrite_rules');
add_action('generate_rewrite_rules', 'bb_add_rewrite_rules');

0 个答案:

没有答案