gpt4 book ai didi

php - WordPress 中单个自定义帖子类型的多个 URL

转载 作者:行者123 更新时间:2023-12-05 05:23:19 25 4
gpt4 key购买 nike

我有一个房地产代理网站,其自定义帖子类型为“property”。因此,当前的 URL 结构是:

/property/the-address-here

现在...在每处特性上,您都可以选择该特性是出售还是出租。我现在想保留单个自定义帖子类型,但单个帖子类型有两个 URL:

/property-for-sale/the-address-here

/property-for-rent/the-address-here

我已经尝试将以下内容添加到我的 .htaccess 中:

RewriteRule ^property-for-sale/([^/]*)/$ /index.php?name=$1 [QSA,L]
RewriteRule ^property-for-rent/([^/]*)/$ /index.php?name=$1 [QSA,L]

但我只是被重定向回原始 URL。

此外,在有人推荐之前,我无法创建新的自定义帖子类型。

感谢任何帮助!

最佳答案

在你的 functions.php 中试试这个:

add_action('init', function()
{
add_rewrite_rule('^property-([^/]+)/([^/]+)/?$', 'index.php?post_type=property&name=$matches[1]', 'top');
}, 0, 0);

参见 add_rewrite_rule()了解更多信息。

关于php - WordPress 中单个自定义帖子类型的多个 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38058749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com