Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WordPress中单个自定义帖子类型的多个URL_Php_Wordpress_.htaccess - Fatal编程技术网

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

Php WordPress中单个自定义帖子类型的多个URL,php,wordpress,.htaccess,Php,Wordpress,.htaccess,我有一个地产代理房地产网站,有一个自定义的“财产”类型的帖子。因此,当前URL结构为: /property/the-address-here 现在。。。在每一处房产上,您可以选择该房产是出售还是出租。我现在想保留单个自定义帖子类型,但对于单个帖子类型有两个URL: /property-for-sale/the-address-here 及 我已尝试将以下内容添加到.htaccess: RewriteRule ^property-for-sale/([^/]*)/$ /index.php?na

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

/property/the-address-here
现在。。。在每一处房产上,您可以选择该房产是出售还是出租。我现在想保留单个自定义帖子类型,但对于单个帖子类型有两个URL:

/property-for-sale/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

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


感谢您的帮助

函数中尝试此操作。php

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

有关更多信息,请参阅。

该页面是Wordpress的一部分吗?因为Wordpress会重定向很多东西,而潜在的答案取决于Wordpress是这样做的,还是一些旧的设置或某种脚本。太棒了!我缺少重定向的post_type=属性部分:)
add_action('init', function()
{
    add_rewrite_rule('^property-([^/]+)/([^/]+)/?$', 'index.php?post_type=property&name=$matches[1]', 'top');
}, 0, 0);