[wp-hackers] any idea why this custom rewrite isnt working?
Chris McCoy
chris at lod.com
Wed May 16 16:45:21 UTC 2012
// multiple keywords works fine domain.com/search/keyword-keyword2.html
from : loop-search.php
$search_query = str_replace('-',' ', $wp_query->query_vars['s']);
$mysearch = new WP_Query("s=$search_query&showposts=-1");
// multiple tag doesnt work domain.com/tag/tag-tag2.html
from: loop-tag.php
$tag_query = str_replace('-',',',$wp_query->query_vars['tag']);
$mytag = new WP_Query("tag=$tag_query&showposts=-1");
// rewrites
add_action('generate_rewrite_rules', 'hotlinkers_add_rewrite_rules');
function hotlinkers_add_rewrite_rules( $wp_rewrite ) {
$new_rules = array(
"^search/(.+)\.html$" => 'index.php?s=' . $wp_rewrite->preg_index(1),
"^tag/(.+)\.html$" => 'index.php?tag=' . $wp_rewrite->preg_index(1)
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_filter('query_vars', 'hotlinkers_queryvars' );
function hotlinkers_queryvars( $qvars ){
$qvars[] = 's';
$qvars[] = 'tag';
return $qvars;
}
add_action('init','hotlinkers_flush_rules');
function hotlinkers_flush_rules(){
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
Thanks ;)
More information about the wp-hackers
mailing list