Conditional arguments WP_Query for post custom fields
Here is a modification of your code where you can add the meta query if certain $GET keys are set. $query_array = array(‘relation’ => ‘AND’); if(isset($_GET[‘gender’]) && !empty($_GET[‘gender’])){ $gender = $_GET[‘gender’]; array_push($query_array, array(‘key’ => ‘wpcf-gender’, ‘value’ => $gender, ‘compare’ => ‘=’)); } if(isset($_GET[‘city’]) && !empty($_GET[‘city’])){ $city = $_GET[‘city’]; array_push($query_array, array(‘key’ => ‘wpcf-city’, ‘value’ => $city, … Read more