Reputation: 3566
I have this code:
$user = get_users( array (
'meta_query' => array(
array(
'meta_key' => 'token',
'meta_value' => '344793879185b4924a7d',
),
'orderby' => 'meta_value',
'order' => 'DESC',
'number' => '10',
)
) );
return count($user);
This returns me all the users.
This returns false
, with notice:
Only variables should be passed by reference in
$user = reset(
get_users(
array(
'meta_key' => 'token',
'meta_value' => '344793879185b4924a7d',
'number' => 1,
'count_total' => false
)
)
);
There is only one user with that metakey with that value.
Upvotes: 0
Views: 700
Reputation: 992
The warning
Only variables should be passed by reference in
is because you are passing the function result directly into reset function which expects a variable.
Apart from that the result that you are getting when using the second code will output a wp_user
object and not an array so resetting the indexing is not actually needed.
Your code should be something like this:
$user = get_users(
array(
'meta_key' => 'token',
'meta_value' => '344793879185b4924a7d',
'number' => 1,
'count_total' => false
)
);
Upvotes: 1