wordpress 如何通过自定义属性过滤 WooCommerce 产品
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15138113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to filter WooCommerce products by custom attribute
提问by
I'm trying to filter WooCommerce product archive by custom attributes.
我正在尝试通过自定义属性过滤 WooCommerce 产品档案。
For example, there are 5 products with attribute "color" containing "red", and another 3 with attribute "color" containing "blue".
例如,“颜色”属性中包含“红色”的商品有 5 件,“颜色”属性中包含“蓝色”的商品有 3 件。
How can I apply a filter to the products loop, so only the products containing "red" will be shown?
如何将过滤器应用于产品循环,以便仅显示包含“红色”的产品?
Thanks
谢谢
采纳答案by jnhghy - Alexandru Jantea
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 选项之一:
$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);
where "$meta_query" is:
其中“$meta_query”是:
$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;
and after that:
在那之后:
query_posts($args);
so you would probably get more info here: http://codex.wordpress.org/Class_Reference/WP_Queryand you can search for "meta_query" in the page to get to the info
所以你可能会在这里获得更多信息:http: //codex.wordpress.org/Class_Reference/WP_Query,你可以在页面中搜索“meta_query”以获取信息
回答by vlood
You can use the WooCommerce Layered Nav widget, which allows you to use different sets of attributes as filters for products. Here's the "official" description:
您可以使用WooCommerce 分层导航小部件,它允许您使用不同的属性集作为产品的过滤器。这是“官方”描述:
Shows a custom attribute in a widget which lets you narrow down the list of products when viewing product categories.
在小部件中显示自定义属性,可让您在查看产品类别时缩小产品列表。
If you look into plugins/woocommerce/widgets/widget-layered_nav.php, you can see the way it operates with the attributes in order to set filters. The URL then looks like this:
如果您查看 plugins/woocommerce/widgets/widget-layered_nav.php,您可以看到它使用属性操作以设置过滤器的方式。该 URL 如下所示:
... and the digits are actually the id-s of the different attribute values, that you want to set.
...而数字实际上是您要设置的不同属性值的 id-s。
回答by Farhad
You can use WooCommerce AJAX Product Filter. You can also watch how the plugin is used for product filtering.
您可以使用WooCommerce AJAX 产品过滤器。您还可以观看该插件如何用于产品过滤。
Here is a screenshot:
这是一个屏幕截图:
回答by user3413723
A plugin is probably your best option. Look in the wordpress plugins directory or google to see if you can find one. I found the one below and that seemed to work perfect.
插件可能是您最好的选择。在 wordpress 插件目录或谷歌中查看是否可以找到。我找到了下面的一个,这似乎很完美。
https://wordpress.org/plugins/woocommerce-products-filter/
https://wordpress.org/plugins/woocommerce-products-filter/
This one seems to do exactly what you are after
这似乎正是你所追求的
回答by dzeriho
Try WooCommerce Product Filter, plugin developed by Mihajlovicnenad.com. You can filter your products by any criteria. Also, it integrates with your Shop and archive pages perfectly. Here is a screenshot. And this is just one of the layouts, you can customize and make your own. Look at demo site. Thanks!
试试WooCommerce 产品过滤器,由Mihajlovicnenad.com开发的插件。您可以按任何标准过滤您的产品。此外,它与您的商店和存档页面完美集成。这是一个屏幕截图。这只是其中一种布局,您可以自定义并制作自己的布局。查看演示站点。谢谢!