I want to get all users with their respective data. I already get all the users:

$users = array();

$users_query = new WP_User_Query( array( 
    'role' => 'subscriber', 
    'orderby' => 'user_registered',
    'number' => 8,
    'order' => 'DESC',
    'fields' => array('ID', 'display_name')
) );
$results = $users_query->get_results();

But I only get the data from user table:

object(stdClass)#3162 (10) {
      string(2) "44"
      string(13) "usuarioprueba"
      string(13) "usuarioprueba"
      string(0) ""
      string(19) "2016-10-13 16:27:56"
      string(1) "0"
      string(14) "Usuario Prueba"
    } ...

How do I get also the data from usermeta without having to use a loop like a foreach


2 Answers 2


All the metadata should be there, you can access them with magic methods.

If you have a metadatum called with the key shoes, you can access it like this


This was under the return fields parameter on WP_User_Query

'all (default) or all_with_meta' - Returns an array of WP_User objects. Must pass an array to subset fields returned.

*'all_with_meta' currently returns the same fields as 'all' which does not include user fields stored in wp_usermeta. You must create a second query to get the user meta fields by ID or use the __get PHP magic method to get the values of these fields.

So, unless this is outdated, it sounds like it's not directly possible.

  • Looking at the code of wp-includes/class-wp-user-query.php, it appears that (at least according to the comments) all_with_meta should return all the users with their metadata.
    – Pat J
    Oct 13, 2016 at 19:20

Your Answer

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

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