【问题标题】:WooCommerce URL to filter by attributeWooCommerce URL 按属性过滤
【发布时间】:2019-04-07 04:20:23
【问题描述】:

我正在尝试根据属性找出在我的商店页面上显示产品所需的 URL。该属性称为“Mantel Type”(slug ma​​ntel-type),术语为“Mantel With Overmantel”(slug ma​​ntel -with-overmantel)。该术语的 ID 为 106。我尝试了以下 URL,但显示的是所有产品,而不是预期的 22,或者我收到 404 错误。

mysite.com/shop/?attribute_mantel-type=Mantel+With+Overmantel

mysite.com/shop/?attribute_mantel-type=mantel-with-overmantel

mysite.com/shop/?taxonomy=pa_mantel-type?&tag_ID=106

mysite.com/shop/?filter_mantel-type=106

mysite.com/shop/?filter_mantel-type=Mantel+With+Overmantel

mysite.com/shop/?filter_mantel-type=mantel-with-overmantel

mysite.com/shop/?pa_mantel-type=Mantel+With+Overmantel(404 错误)

mysite.com/shop/?pa_mantel-type=106(404 错误)

我已确保已在 Mantel Type 属性编辑器中选中了启用存档复选框。

我在产品类别方面取得了成功,但不是属性。此产品类别链接有效,例如:

mysite.com/shop/?product_cat=french

如何在 URL 中也包含属性?感谢您的宝贵时间。

【问题讨论】:

    标签: wordpress woocommerce attributes


    【解决方案1】:

    Woocommerce 属性只是 Wordpress 分类法。

    https://example.com/mantel-type/mantel-with-overmantel/ 会得到你想要的。我想有一些方法可以让https://tart.dolcedev.com/shop/mantel-type/mantel-with-overmantel/ 去你想要的,但我对你的 wp 设置知之甚少,无法提供帮助。

    您也可以使用get_term_link 动态生成这些网址。 https://developer.wordpress.org/reference/functions/get_term_link/

    带有“?”的网址全部转到“商店”页面。 url 中的任何内容都以 ?只是一个查询字符串。

    【讨论】:

    • 谢谢!这确实有效,但我需要一次显示属性+类别过滤器的组合......我可以获得非漂亮版本吗?查询网址?另外,你能帮我一个忙,用“mysite”替换你的网址吗?我正在努力保护网站的身份。
    • 当然!更换。据我所知,你真的不能用蛞蝓做到这一点……它们特定于单个术语。 wordpress 使用查询来获取内容,而不是查询 url。您在“商店”页面上有一些过滤器插件(或者可能是原生 woocommerce 过滤器?),它们正在生成这些插件,但对于存档页面,wordpress 运行查询。我建议为您需要的不同组合构建自定义存档页面模板。不过,您必须为每种组合构建一个单独的组合。
    猜你喜欢
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 2020-08-30
    • 2021-03-30
    • 2016-02-20
    • 1970-01-01
    • 2020-08-03
    相关资源
    最近更新 更多