3

How do I get a list of all users with role = 'Customers' including all the metadata per user, means wp_users + wp_usermeta.

Query below does not generate the wanted results.

    $query = "SELECT * FROM wp_users INNER JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id ORDER BY ID DESC');  ";

    $data = $wpdb->get_results($query,ARRAY_A);

But that list is not correct. It shows each user x times depend of the amount of rows in wp_usermeta.

How can i filter it? That each user shows per record all his user + metadata?

Still searching for 6 hours.

  • Check this – bravokeyl Jun 29 '16 at 13:46
  • but then I need to different calls 1 for user 1 for metadata. How do I combinate them? – Hermants Jun 29 '16 at 13:51
  • 1
    And that call is?? – Hermants Jun 29 '16 at 13:58
10

I think you should use wp-api functions which will do everything for you.

  • get_users() function will get all users data just define fields which u require.
  • get_user_meta() function will get usermeta data.
 
$users = get_users( array( 'fields' => array( 'ID' ) ) );
foreach($users as $user_id){
        print_r(get_user_meta ( $user_id->ID));
    }
-1

You can use WordPress' built-in API functions which will get all the User's data + user metadata from the database.

  • get_users() function will get all users data. Specify the parameters which you need to get from the database

  • get_user_meta() function will get usermeta data.

    $users = get_users( array( 'fields' => array( 'ID' ) ) );
    foreach($users as $user_id) {
        print_r(get_user_meta ( $user_id->ID));
    }
    

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.