WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#20095 closed defect (bug) (worksforme)

get_users() doesn't allow hyphens in meta_key parameter

Reported by: mordauk Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3.1
Component: Users Keywords: reporter-feedback
Focuses: Cc:

Description

When retrieving users with the get_users() function, the meta_key parameter does not work if the key contains a hyphen (dash).

For example:

$members = get_users(array(
		'meta_key' => 'job-seeking',
		'meta_value' => 1,
	)
);

That will result in no members being found, even though at least one user with a meta_key of "job-seeking" with a value of 1 does exist.

This, however, will work:

$members = get_users(array(
		'meta_key' => 'job_seeking',
		'meta_value' => 1,
	)
);

Change History (4)

#1 @hakre
9 years ago

  • Keywords reporter-feedback added

Can you clarify if the meta key is job-seeking or job_seeking in the database data?

It might just be that meta keys are normalized.

#2 @mordauk
9 years ago

  • Keywords changed from needs-testing, reporter-feedback to needs-testing reporter-feedback

It's not, it definitely has the hyphen.

Doing get_user_meta($user_id, 'job-seeking', true) works fine (returns the value).

Doing update_user_meta($user_id, 'job-seeking', 1) also works fine and saves the data.

I've also just looked through the usermeta table and there are lots of keys with hyphens, so they're not getting normalized upon creation. At least as far as I can tell.

#3 @iseulde
8 years ago

  • Keywords needs-testing removed
  • Resolution set to worksforme
  • Status changed from new to closed

Works for me in 3.6.

#4 @helen
8 years ago

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