WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 am using a plugin to create custom fields in the user registration.

I have created a check box field called g300 which is the name of the meta_key stored in wp_usermeta.

It looks like the value in the database is a comma when the checked it off.

How could I return a list of users that checked off this box?

share|improve this question
up vote 1 down vote accepted

I haven't touched user functions so far, but according to the codex, should look something like this.

 $args = array(
      'meta_key' => 'g300',
      'meta_value' => ','

 $users = get_users( $args );


This assumes that all the users with the field unchecked have a comma value ( for example, it won't work if the value in the DB is empty ).

Example 2

 $args = array(
      'meta_key' => 'g300',
      'meta_value' => 'I will attend the G300 class,' //Was the comma intentional? If not, remove

 $users = get_users( $args );

 if( !empty( $users ) )
      foreach( $users as $user )
           echo $user->display_name; //name
           echo $user->user_email; //email

           $meta = get_user_meta( $user->ID, 'is_700_a', TRUE );

           echo $meta; //the meta field value
share|improve this answer
That should only output the users with g300 checked right? I'm not getting any results. – Shae Jan 23 '12 at 13:14
Well you said above "It looks like the value in the database is a comma when the checked it off", so it should return those who checked it off. If you want those that have it checked, replace the comma with the appropriate value. – Shane Jan 23 '12 at 15:00
Ok, you are right it is "I will attend the G300 class,". So I am trying to output some information on users who have that option. How do i echo it out? I was able to get the email with this: <?php $args = array('meta_key' => 'g300', 'meta_value' => 'I will attend the G300 class,');?> <?php $blogusers = get_users($args); foreach ($blogusers as $user) { echo '<div>' . $user->user_email . '</div>';} ?> – Shae Jan 30 '12 at 19:15
What do you mean how? You managed to echo the user_email, you can echo the other information the same way. Look at this link, "Returns" section has a list of info that's in the user object. codex.wordpress.org/Function_Reference/get_users#Returns – Shane Jan 30 '12 at 20:51
Ok, let me explain what I am trying to do. I created custom fields in user registration. all of them are stored in wp_usermeta. I need to return a list of only the users who checked off 'g300' which creates the value 'I will attend the G300 class,'. I need to return the details of the users who checked this value off. The details need to include first and last name, email address, and the value of another custom field called 'is_700_a'? It looks like the only value not stored in wp_usermeta is the emall address. which is stored in wp_users. – Shae Feb 2 '12 at 14:24

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.