你应该钩住add_rewrite_rule()
进入init
假设http://local/rieltplus/
是您的主页,并且category/catalog/
是一类档案,这应该可以:
add_action(\'init\', function() {
add_rewrite_rule(
\'category/catalog/([^/]+)?$\',
\'index.php?category_name=catalog&type=$matches[1]&price_min=1000&price_max=2000&area_min=5&area_max=50&room_num=5&etage=2&plan=old\',
\'top\'
);
});
如果你想让任何类别都可以使用它,那么在评论中提及它。
顺便说一句local/rieltplus/category/catalog/TYPE&price_min
不是有效的URL,与local/rieltplus/category/catalog/TYPE?price_min
或local/rieltplus/category/catalog/TYPE/?price_min
..
获取type
变量,使用get_query_var( \'type\' )
但首先将其添加到主查询:
add_filter(\'query_vars\', function($vars) {
$vars[] = "type";
return $vars;
});
您应该通过将permalink结构保存在
settings > permalinks
屏幕或使用
flush_rewrite_rules()
只有一次。
Edit - 根据你在the comments
add_action(\'wp\', function() { // this will work as long as GET type is the first is the query string
if( "catalog" === get_query_var( "category_name" ) && isset( $_GET["type"] ) ) {
if( ! empty( $_GET["type"] ) ) {
$type = strval( $_GET["type"] );
$url = $_SERVER["REQUEST_URI"];
$url = str_replace( array( "?type={$type}&", "?type={$type}" ), "{$type}?", $url );
$url = str_replace( "?&", \'?\', $url );
wp_redirect( $url );
exit;
}
}
});