Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#32603 closed defect (bug) (duplicate)

User meta query can return same user multiple times

Reported by: sccr410's profile sccr410 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)

#1 @knutsp
9 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #32592.

#2 @netweb
9 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.