Woocommerce: Show products filtered by attribute

2020-04-30 08:02发布

I want to filter products by attribute in Woocommerce using a checkbox or alternatively a link. If I mark the checkbox or click the link I want get all products that have this attribute.

How can I do this? Which files should I edit?

Edit: Now i need do a query to get all products that have a custom attribute 'demo' in my case.

I'm doing this:

$args = array ( 'meta_query' => array( 
array( 'key' => 'meta_value', 
       'value' => 'demo', 
       'compare' => 'LIKE', ), 
       ), 
);

Whats wrong??

Thanks!

1条回答
ら.Afraid
2楼-- · 2020-04-30 08:41

Ok i got finally the result!

I have this:

$args = array ( 
     'post_type'  => 'product',
     'posts_per_page'  => 12,
     'meta_query' => array( 
         array( 
          'value' => 'demo', 
          'compare' => 'like'
         ), 
       ), 

);

Thanks anyway for the help!

查看更多
登录 后发表回答