我试图重写以下URL在WP: http://www.example.com/?compra=arriendo&propertytype=apartamentos&location=bogota&habitaciones=2-habitacionesWordPress的URL重写 - 可选值
到: http://www.viveya.co/arriendo/apartamentos/bogota/2-habitaciones
这是我的代码:
功能eg_add_rewrite_rules(){ global $ wp_rewrite;
$new_rules = array( '(.+)/(.+)/(.+)/(.*)/?$' => 'index.php?compra=' . $wp_rewrite->preg_index(1) . '&propertytype=' .
$ wp_rewrite-> preg_index(2)。 '& location ='。 $ wp_rewrite-> preg_index(3) 。 '& habitaciones ='。 $ wp_rewrite-> preg_index(4) ); $ wp_rewrite-> rules = $ new_rules + $ wp_rewrite-> rules;
}
ADD_ACTION( 'generate_rewrite_rules', 'eg_add_rewrite_rules');
现在,我想向城市显示是可选的。所以,如果我输入以下URL: http://www.viveya.co/arriendo/apartamentos/bogota/
它仍然会工作。 (原始URL将为& habitaciones =)。当城市显示为空
我的代码不能正常工作。我不知道为什么。我的正则表达式有什么问题?
在此先感谢! 亚当
为什么您没有在[WPSE](http://wordpress.stackexchange.com/)上发布此信息的具体原因? – scribu 2012-05-03 10:56:49