0

Trying to get the user's login, by searching for the current user with a custom field value (meta_value). The problem is that i get the same result, even when i try to provide false meta_value, to test the "not found" part of my code. So far i have this.

$user = reset(
    get_users(
        array(
            'meta_key' => 'egt_session_key',
            'meta_value' => 'some_custom_field_data',
            'number' => 1,
            'count_total' => false
        )
    )
);


$user = get_users($user);
echo $user[0]->data->user_login;
0

You may update your query like this :

get_users(
    array(
        'number' => 1,
        'count_total' => false,
        'meta_query'=> array(
            array(
               'key' => 'egt_session_key',
               'compare' => '=', 
               'value' => 'some_custom_field_data'
           )
       )
    )
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.