我们可以使用 WC_Products_Query 来获取与所需产品名称匹配的产品吗?

Can we use WC_Products_Query to get products that matches a desired product name?

我有这样的要求:

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

Possible solutions using [do_shortcode] generates unwanted HTML, it is undesired.

$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

samsung galaxy s10+

samsung qled tv

galaxy chocolate

microsoft surface mobile pc

用以下内容替换您的查询 -

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