Php 通过add_url_rewrite从自定义分类和自定义帖子类型中删除slug

Php 通过add_url_rewrite从自定义分类和自定义帖子类型中删除slug,php,wordpress,.htaccess,url-rewriting,custom-post-type,Php,Wordpress,.htaccess,Url Rewriting,Custom Post Type,问题: 有一个名为product_category的自定义分类法和一个名为slug as product的自定义帖子类型。现在url看起来是这样的 example.com/categories/laptop 和产品职位 example.com/product/laptop/acer/acerlaptopname 现在我想让他们表现得像这样: example.com/laptop 同样地 example.com/laptop/acer/acerlaptopname 尝试过的解决方案: 使用.hta

问题:

有一个名为product_category的自定义分类法和一个名为slug as product的自定义帖子类型。现在url看起来是这样的

example.com/categories/laptop

和产品职位

example.com/product/laptop/acer/acerlaptopname

现在我想让他们表现得像这样:

example.com/laptop

同样地

example.com/laptop/acer/acerlaptopname

尝试过的解决方案:

  • 使用.htaccess的解决方案:
  • 由于内部wordpress url重写规则,此解决方案无法工作

  • 已尝试使用添加url重写解决方案:
  • 我在functions.php中添加了以下代码,然后刷新

    在第一部分中,我添加了这段代码,并发现

    example.com/laptop/acer/acerlaptopname    --> as needed
    

    两人都在跑步

    添加操作('init',函数() { 添加重写规则(“^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$”,“index.php?post_type=product&product_category=$matches[1]&product_brand=$matches[2]&name=$matches[3],“top”); }, 0, 0); ?>
    example.com/product/laptop/acer/acerlaptopname  --> not needed