如何通过自定义属性过滤WooCommerce产品 [英] How to filter WooCommerce products by custom attribute

查看:226
本文介绍了如何通过自定义属性过滤WooCommerce产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过自定义属性过滤WooCommerce产品归档.

I'm trying to filter WooCommerce product archive by custom attributes.

例如,有5种产品的颜色"属性包含红色",另外3种产品的颜色"属性包含蓝色".

For example, there are 5 products with attribute "color" containing "red", and another 3 with attribute "color" containing "blue".

如何对产品循环应用过滤器,这样只会显示包含红色"的产品?

How can I apply a filter to the products loop, so only the products containing "red" will be shown?

谢谢

推荐答案


在我的一个网站上,我不得不通过大量数据进行自定义搜索,其中一些来自自定义字段,这是我的$ args看起来像其中一种选项的方式:


On one of my sites I had to make a custom search by a lot of data some of it from custom fields here is how my $args look like for one of the options:

$args=array('meta_query'=>$meta_query,'tax_query'=>array($query_tax),'posts_per_page' => 10,'post_type' => 'ad_listing','orderby'=>$orderby,'order'=>$order ,'paged'=>$paged);


其中"$ meta_query"为:


where "$meta_query" is:

$key="your_custom_key"; //custom_color for example
$value="blue";//or red or any color
$query_color = array('key' => $key, 'value' => $value);
$meta_query[] = $query_color;

之后:

query_posts($args);

,因此您可能会在此处获得更多信息: http://codex.wordpress.org/Class_Reference/WP_Query 您可以在页面中搜索"meta_query"以获取信息

so you would probably get more info here: http://codex.wordpress.org/Class_Reference/WP_Query and you can search for "meta_query" in the page to get to the info

这篇关于如何通过自定义属性过滤WooCommerce产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆