Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Timothy Jacobs on "WP Metadata User Query on non-existent fields"

$
0
0

Hi all,

I am using the WP_User_Query class, and the meta search ( meta_key, meta_value, meta_compare ) capabilities.

I am trying to do a search for all users who do not have a certain meta_key set to true. However, if the metadata does not exist for the user, then WP_User_Query doesn't return that user, despite the fact that I am using != as the comparison.

Here is my code, any thoughts?

$query = new WP_User_Query( array(
		  'role'         => 'some_slug,
		  'meta_key'     => 'some_sort_of_meta_key',
		  'meta_value'   => 1,
		  'meta_compare' => "!=",
		  'number'       => 25,
		  'offset'       => $user_offset
		) );
		$users = $query->get_results();

Thanks!


Viewing all articles
Browse latest Browse all 8245

Trending Articles