Make WordPress Core

Opened 15 years ago

Closed 13 years ago

Last modified 13 years ago

#20095 closed defect (bug) (worksforme)

get_users() doesn't allow hyphens in meta_key parameter

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

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
15 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
15 years ago

  • Keywords needs-testing, reporter-feedback → 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
13 years ago

  • Keywords needs-testing removed
  • Resolution → worksforme
  • Status new → closed

Works for me in 3.6.

#4 @helen
13 years ago

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