D
D
Dr Zhmurge2021-09-21 18:25:47
WooCommerce
Dr Zhmurge, 2021-09-21 18:25:47

How to make a selection of products by attributes (taxonomies) in the range between?

tax_query does not have a 'BETWEEN' comparison operator, unlike meta_query. Is it possible to somehow use taxonomies for sampling in the range from and to?

$args['tax_query'][] = array(
            'relation' => 'AND',
            array(
              'taxonomy' => 'pa_vysota',
              'field' => 'name',
              'terms' => array(140, 1200),
              'compare' => 'BETWEEN' //это не работает
            )
          );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2021-09-21
@DrZhmurge

There is no BETWEEN in tax_query because the meaning of the search is generally different. Try to userange()

'tax_query' => array(
  array(
    'taxonomy' => 'pa_vysota',
    'field'    => 'id',
    'terms'    => range( 140, 1200 )
  )
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question