R
R
rkfddf2020-07-02 10:35:16
WordPress
rkfddf, 2020-07-02 10:35:16

Is it possible to filter in wordpress via wp_query() considering all fields?

Is it possible to filter in wordpress via wp_query() considering all fields? That is, all fields must be taken into account

'meta_query' => [
    'relation' => 'OR',
    [
      'key' => 'color',
      'value' => array('red', 'blue', 'white'),
                         'compare' => '='

    ],
    [
      'key' => 'price',
      'value' => array('20', '50', '180'),
                        'compare' => '='
    ],
[
      'key' => 'age',
      'value' => array('20', '30', '40'),
                         'compare' => '='
    ]
  ]

And at the same time, there are more than two condition fields. I found pictures, like this is implemented via wp_query(), but I can't find the code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Chesnokov, 2020-07-09
@rkfddf

If "value" is an array then "compare" can only be: IN, NOT IN, BETWEEN, NOT BETWEEN.

'meta_query' => [
  'relation' => 'AND',
  [
    'key' => 'color',
    'value' => array('red', 'blue', 'white'),
    'compare' => 'IN'
  ],
  [
    'key' => 'price',
    'value' => array('20', '50', '180'),
    'compare' => 'IN'
  ],
  [
    'key' => 'age',
    'value' => array('20', '30', '40'),
    'compare' => 'IN'
  ]
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question