私はWPで、次のURLをリライトしようとしています: 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(){ グローバル$ wp_rewrite;
$new_rules = array( '(.+)/(.+)/(.+)/(.*)/?$' => 'index.php?compra=' . $wp_rewrite->preg_index(1) . '&propertytype=' .
$ wp_rewrite-> preg_index(2)。 '&場所='。 $ 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')。
今、私はhabitacionesをオプションにします。したがって、次のURLを入力した場合: http://www.viveya.co/arriendo/apartamentos/bogota/
これはまだ動作します。 (元のURLは& habitaciones =)になります。
habitacionesが空の場合、私のコードは機能しません。なぜ私は考えていない。私の正規表現で何が間違っていますか?
ありがとうございます! Adam
[WPSE](http://wordpress.stackexchange.com/)にこれを投稿しなかった特別な理由はありますか? – scribu