K
K
kolibry12016-10-21 11:36:15
PHP
kolibry1, 2016-10-21 11:36:15

How to access woocommerce product categories using wp_query?

Good afternoon.
You need to display products of a certain category in the page template.
I wanted to ask how to refer to the category (what are they called)? woocommerce plugin.
Apparently you need something like this

$args__ = array(
  'post_type'			=> 'product',
  'posts_per_page'	=> -1,
  'tax_query' = array(
array(
'key' => 'product_cat',
'value' = > 'cables',
)
)
);

but product_cat doesn't roll

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2016-10-21
@kolibry1

key/value is for meta_query, otherwise for tax_query

$args = array(
    'posts_per_page' => -1,
    'post_type' => 'product',
    'tax_query' => array(
        array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => 'cables'
        ),
    ),  
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question