我有一个问题,我试图为seo创建干净的URL。但是我没有使用get获取任何参数,这在我的代码中是错误的
add_action( \'init\', \'listing_search_url\' );
function listing_search_url()
{
add_rewrite_tag(\'%type%\', \'([^&]+)\');
add_rewrite_tag(\'%search_location%\', \'([^&]+)\');
add_rewrite_rule(
\'^custom(/([^/]+))?/(/([^/]+))?/?\',
\'index.php?page_id=23&type=$matches[2]&search_location=$matches[4]\',
\'top\'
);
flush_rewrite_rules();
}
这项工作,但有错误,所以我只是做了一个改变,工作完美
function wpd_foo_get_param() {
if( false !== get_query_var( \'search_location\' ) ){
$_GET[\'search_location\'] = get_query_var( \'search_location\' );
}
}
add_action( \'parse_query\', \'wpd_foo_get_param\' );
此代码有效
add_action( \'parse_query\', \'listing_get_query_vars\' );
function listing_get_query_vars() {
//if you use - _ + on your url the form just recive a space
if(!empty( get_query_var( \'search_location\' )) ){
$_GET[\'search_location\'] = str_replace(array(\'-\',\'_\',\'+\'),\' \',get_query_var( \'search_location\' ));
}
}