R
R
rkfddf2020-06-27 16:52:24
WordPress
rkfddf, 2020-06-27 16:52:24

How to correctly fill WP_Query{} wordpress arguments?

Through acf created fields "sex", "profession". Then through a simple form I want to filter the records

<form method="POST">
      <div> </div>
      <input name="wsex[]" value="Male" type="checkbox">      Мужчина <br>
      <input name="wsex[]" value="Female"        type="checkbox"> Женщина <br>
      <div>        <hr>
 <input name="wprofession[]" value="cook"      type="checkbox"> повар <br>
        <input name="wprofession[]" value="watchman"      type="checkbox"> сторож <br>
      </div>
    </form>

I want to display suitable posts through WP_Query {}. I'm trying to output like this
$args = [
  'meta_query' => [
    'relation' => 'OR',  // AND
    [
      'key' => 'sex',
      'value' => $_POST['wsex']
    ],
    [
      'key' => 'profession',
      'value' => $_POST['wprofession']
    ]
  ]
];


And then a parade of errors begins - either types are not defined, then nothing is displayed, then all posts are immediately displayed. How to properly populate key and value in multiple select?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question