【问题标题】:Can we use WC_Products_Query to get products that matches a desired product name? [closed]我们可以使用 WC_Products_Query 来获取与所需产品名称匹配的产品吗? [关闭]
【发布时间】:2019-12-26 10:57:58
【问题描述】:

我有这样的要求:

  1. 用户搜索产品
  2. 必须返回与搜索字符串中的至少一个单词匹配的任何产品名称
  3. 必须按降序排列,最高的结果具有最多的匹配词
  4. 产品的短或长描述不需要检查关键字

使用[do_shortcode] 的可能解决方案会生成不需要的 HTML,这是不受欢迎的。

$products = wc_get_products(array(
  'category'                              => array($brand_slug),
  'status'                                => 'publish',
  'limit'                                 => 20,
  'orderby'                               => 'date',
  'order'                                 => 'DESC',
  'return'                                => 'objects'
  'query'                                 => array(
    'title'                               => $title // Something like this
  )
));

搜索查询samsung galaxy mobile的预期输出:

三星 Galaxy s10+

三星qled电视

银河巧克力

微软 Surface 移动电脑

【问题讨论】:

    标签: wordpress woocommerce wordpress-theming custom-wordpress-pages


    【解决方案1】:

    将您的查询替换为以下内容 -

    $products = wc_get_products(array(
      'category'                              => array($brand_slug),
      'status'                                => 'publish',
      'limit'                                 => 20,
      'orderby'                               => 'date',
      'order'                                 => 'DESC',
      'return'                                => 'objects'
      's'                                     => $title, // Something like this
    ));
    

    【讨论】:

    • 感谢您抽出宝贵时间。唉,它没有用。 Source
    • 我改变了我的方法来做到这一点。
    猜你喜欢
    • 1970-01-01
    • 2010-10-10
    • 1970-01-01
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多