1

I am using UltimateMember and I have the settings configured that admin must approve registered users first. I now want to display the approved users meta information like faculty, email, etc. in the theme. So in this page template I've the following block of code to get all registered users information :

<?php
$args = array(
    'role' => 'contributor',
);

$users = get_users( $args );

foreach ( $users as $user ) {
    echo '<span>' . esc_html( $user->user_email ) . '</span>';
    echo '<span>' . esc_html( $user->faculty ) . '</span>';
    echo '<span>' . esc_html( $user->graduation_year ) . '</span>';
}

The problem is, that my code block is displaying all registered users information weather it is approved by admin or not.

2
  • Try who parameter instead of role. who - If set to 'authors', only authors (user level greater than 0) will be returned.
    – Webloper
    Jul 26, 2015 at 17:37
  • this even displayed admin information , i want to get users labeled 'approved' in the plugin and exclude users with status 'pending review' Jul 26, 2015 at 19:18

2 Answers 2

2

I assume your WP settings is

  1. New User Default Role = contributor

If yes, so this block of code shows all the contributor's with account_status = approved;

$args = array(
    'role'          =>  'contributor',
    'meta_key'      =>  'account_status',
    'meta_value'    =>  'approved'
);

$users = get_users($args);

foreach ($users as $user) {
   echo '<pre>';
   print_r( $user );
   echo '</pre>';
}

https://codex.wordpress.org/Function_Reference/get_users

3
  • great worked , i appreciate your help but can you explain to me how did you know there is a meta key with the name 'account_status' ? Jul 26, 2015 at 19:59
  • Through guess first then checked into database. ;)
    – Webloper
    Jul 26, 2015 at 20:07
  • Yeah i wanted to to check in database but did not know where to dig exactly Jul 27, 2015 at 7:28
0

The plugin called Ultimate Member has this capability via the Ultimate Member settings > User roll.

Plugin URL: https://wordpress.org/plugins/ultimate-member/

Your Answer

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

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