#32603 closed defect (bug) (duplicate)
User meta query can return same user multiple times
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 4.2.2 |
| Component: | Users | Keywords: | |
| Focuses: | Cc: |
Description
Below is my sample arguments array when doing a zipcode search on users. We store zipcodes in two meta fields: their actual address zipcode and (optionally) additional zipcodes (comma separated) the user provides service in.
$zipcode = 'XXXXX'; // The user submitted zipcode for the search
$target_zipcodes = array(); // This array is created by doing a typical zipcode radius search and populated with zipcodes within X mile radius of the searched zipcode
$args = array(
'exclude' => array($current_user->ID),
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => 'zipcode',
'value' => $target_zipcodes,
'compare' => 'IN'
),
array(
'key' => 'additional_zipcodes',
'value' => $zipcode,
'compare' => 'LIKE',
),
),
array(
'key' => 'status',
'value' => 'active',
),
),
'orderby' => 'meta_value',
'order' => 'ASC'
);
In an instance where the zipcode searched is in the $target_zipcode array and is in the "additional_zipcodes" user meta value, the user ID is returned twice. So my search results are listing the user two times, I assume because of a bug in the "OR" relation. I feel any query for users should never return the same user twice.
Change History (2)
Note: See
TracTickets for help on using
tickets.
Duplicate of #32592.