0

WordPress 忍者の皆さん、こんにちは。

ワードプレス開発初心者です。hereおよびhereの例にあるものと同様に、(タグを使用して)書き換えルールを定義します。

$wp_rewrite->add_rewrite_tag('%filterx_location%', '([^&/]+)', 'filterx_location=');
$wp_rewrite->add_rule('property-location/(.+)$','index.php?post_type=property&filterx_location=$matches[1]', 'top');

問題は、クエリが完了したとき (ページが表示されたとき)、filterx_location パラメーターが設定されていないことです。実際、var_dump($_GET)私にarray(0) { }.

私はブラックアウトか何かを持っています、私がここで見逃している単純なもののように思えます、ただそれを理解することはできません:-/

どんな助けでも大歓迎です!

アップデート

さらに奇妙なのは、次のように書き換えルールを生成するときです。

$wp_rewrite->add_rewrite_tag('%filterx_location%', '([^/]+)', 'filterx_location=');
$permalink_prefix = 'property-location'; 
$permalink_structure = '%filterx_location%/'; 
$rewrite_rules = $wp_rewrite->generate_rewrite_rules($permalink_prefix.'/'.$permalink_structure, EP_ALL, true, true, true, true, true);

それらを印刷すると、生成されたURLの一致とリダイレクトがたくさん表示されます。それらの1つは次のとおりです。

property-location/([^/]+)/page/?([0-9]{1,})/?$ => index.php?filterx_location=$matches[1]&paged=$matches[2]&post_type=property

生成されたすべての URL を次のように追加します。

foreach($rewrite_rules as $regex => $redirect) {
    if(strpos($redirect, 'attachment=') === false) {
        //add the post_type to the rewrite rule
        $redirect .= '&post_type=property';
    }

    //turn all of the $1, $2,... variables in the matching regex into $matches[] form
    if(0 < preg_match_all('@\$([0-9])@', $redirect, $matches)) {
        for($i = 0; $i < count($matches[0]); $i++) {
            $redirect = str_replace($matches[0][$i], '$matches['.$matches[1][$i].']', $redirect);
        }
    }
    //add the rewrite rule to wp_rewrite
    $wp_rewrite->add_rule($regex, $redirect, 'top');
}

URL にアクセスすると/property-location/madrid/page/2/、query_vars には ["paged"]=> int(2) が正しく含まれています。しかし、filterx_location は完全に無視されます!

4

1 に答える 1