From form to wp_query(); the values ​​of the meta-fields of the record that need to be sampled, that is, simply

 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'key1', 'value' => $_GET['value1'], ), array( 'key' => 'key2', 'value' => $_GET['value2'], ), ) 

How to make it so that if an empty value is transferred, records with any value of this field are displayed, that is, change to

 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'key1', 'compare' => 'EXISTS' ), array( 'key' => 'key2', 'value' => $_GET['value2'], ), ) 

    1 answer 1

    Found the answer. Define an array as a variable, and, depending on the data transferred, send it to an array of arguments.

     if (!empty($_GET["key1"])) { $key = array( 'key' => 'key1', 'value' => $_GET['value1'] ); } else { $key = array( 'key' => 'key1', 'compare' => 'EXISTS' ); } 'meta_query' => array( 'relation' => 'AND', $key )