[wp-trac] [WordPress Trac] #32603: User meta query can return same user multiple times
WordPress Trac
noreply at wordpress.org
Tue Jun 9 23:24:00 UTC 2015
#32603: User meta query can return same user multiple times
--------------------------+-----------------------------
Reporter: sccr410 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Users | Version: 4.2.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32603>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list