WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a plugin needing to return avatars a specific way. If the user exists in the wp_users table the code is run else a different set of code is run if the user is not in the wp_users table. I cannot use the username_exist and am tinkering now with the idea of using the user_status value of 0.

From the Codex, code is possible to return information based on the user_status

        $blogusers = get_users('user_status=0');
        foreach ($blogusers as $user) {
            echo '<li>' . $user->user_email . '</li>';

This returns the email address for the users in the wp_users table.

But I want to use a conditional ...

The following works on a local development server in which $id is 1. But not everyone using the plugin will have just this one user id ...

        if ( $id == '1' ) { 

        // echo 'User ID is ' . $id;

        // Do something here

    } else {

        // the user is not in WordPress do something cool   


How can I use the user_status in a conditional to check if the user_status is 0 then do something else run the code the user not being in the WP users table.

In other words, how can I write a conditional to check user_status = 0?

share|improve this question
$blogusers = get_users();
    foreach ($blogusers as $user) {
              //do something
            // do something else
share|improve this answer
Thank you for the suggestion but that doesn't seem to work. The issue is the $user->user_status == '0' isn't allowing the else to run for non WP users. – LPH Mar 11 '14 at 5:53
@LPH where do you store non wp users? what do you mean by non wp users? – Rajeev Vyas Mar 11 '14 at 6:02
OK. Turns out I was setting the user_status to 0 in another function. Removed it. Now that code works with simply the if ($user->user_status == '0') Thank you for the help. Update -- Nope -- Typed too soon. This still doesn't work properly. – LPH Mar 11 '14 at 6:03
@LPH you can accept the answer if use full. – Rajeev Vyas Mar 11 '14 at 6:03
@RajeevVyas: Please don't pose a code block without any explanation. Edit your answer and say how the code can benefit. – Mayeenul Islam Mar 11 '14 at 7:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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