Help with WP_User_Query user meta field search and filter
-
I’m in the process of building out a frontend AJAX search and filter page for users, that I need to search and filter results by a variety of custom meta fields. I’ve used ACF to create the meta fields in the database, and have an AJAX implementation working that will collect the data from the form and pass it to my PHP callback function. Only thing is, regardless of how I craft the query arguments for the search, I’m not getting results returned from the database. I’ve echoed out all the values that I’m passing via AJAX to make sure that they’re coming through (try a search on the attached page link, and you’ll see the big list of values appear before the search results), and I’ve made sure all the form values match the meta values that are in the user meta database fields. Some of the fields contain array data, and some just a regular string. I feel like I’ve tried every comparison or matching rule in the codex. Why are results not returning?
Here’s my query arguments that are in the PHP callback://Get Search and filter values from Ajax $mediator_search = $_POST['mediator_search']; $designations = $_POST['designations']; $region = $_POST['region']; $languages = $_POST['languages']; $hourly_rates = $_POST['hourly_rate']; $associate = $_POST['associate']; $sliding_scale = $_POST['sliding_scale']; $indigenous_mediator = $_POST['indigenous_mediator']; //Dynamically create variables from form values that contain arrays - each created variable will be formatted 'designation_[number]' $designation_count = 1; foreach ($designations as $designation) { $des = 'designation_'.$designation_count; $$des = $designation; $designation_count++; } $args = array( 'role' => 'mediator', 'number' => $per_page, 'paged' => $paged, 'order' => 'ASC', 'meta_query' => array( 'relation' => 'AND', array( // Values in this meta field are an array 'key' => 'designations', 'value' => array ( $designation_1 ), 'compare' => 'IN' ), array( 'key' => 'region', 'value' => $region, 'compare' => 'LIKE' ), array( 'key' => 'associate', 'value' => $associate, 'compare' => '=' ), array( 'key' => 'sliding_scale', 'value' => $sliding_scale, 'compare' => '=' ), // The value in this meta field is either a 1, or nothing array( 'key' => 'indigenous_mediator', 'value' => $indigenous_mediator, 'compare' => '=' ), // Trying to search keywords from a search form field here array( 'key' => 'first_name', 'value' => $mediator_search, 'compare' => 'LIKE' ), array( 'key' => 'last_name', 'value' => $mediator_search, 'compare' => 'LIKE' ), array( 'key' => 'region', 'value' => $mediator_search, 'compare' => 'LIKE' ), ) );
Thanks in advance, and please let me know if any other details are needed!
The page I need help with: [log in to see the link]
- The topic ‘Help with WP_User_Query user meta field search and filter’ is closed to new replies.