1

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?

1 Answer 1

0

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 );

EDIT

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
      }
 }
8
  • That should only output the users with g300 checked right? I'm not getting any results. Commented Jan 23, 2012 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. Commented Jan 23, 2012 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>';} ?> Commented Jan 30, 2012 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 Commented Jan 30, 2012 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. Commented Feb 2, 2012 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.