Make WordPress Core

Opened 2 years ago

Closed 8 months ago

Last modified 8 months 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:


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)

comment:1 hakre2 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.

comment:2 mordauk2 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.

comment:3 avryl8 months ago

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

Works for me in 3.6.

comment:4 helen8 months ago

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