Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
$wp_user_search = new WP_User_Query( array( 'role' => 'author' ) );
$author_list = $wp_user_search->get_results();

foreach($author_list as $author)
{
  // author properties?
}

Can you point me in the direction of the documentation of what properties $author has?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Either an array of row objects with properties the column names of the result of the SQL query - ie. the specified fields from the wp_users table or, if fields equals 'all_with_meta', an array of WP_User objects.

The fields value defaults to 'all', which will return all the columns in the wp_users table, but can be overridden by passing an array of specified fields - and is parsed as follows:

              if ( is_array( $qv['fields'] ) ) {
                        $qv['fields'] = array_unique( $qv['fields'] );

                        $this->query_fields = array();
                        foreach ( $qv['fields'] as $field )
                                $this->query_fields[] = $wpdb->users . '.' . esc_sql( $field );
                        $this->query_fields = implode( ',', $this->query_fields );
                } elseif ( 'all' == $qv['fields'] ) {
                        $this->query_fields = "$wpdb->users.*";
                } else {
                        $this->query_fields = "$wpdb->users.ID";
                }

see the query function in the WP_User_Query class definition - where the query results is replaced with WP_User objects if 'fields' is 'all_with_meta'

       function query() {
                global $wpdb;

                if ( is_array( $this->query_vars['fields'] ) || 'all' == $this->query_vars['fields'] ) {
                        $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
                } else {
                        $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
                }

                if ( $this->query_vars['count_total'] )
                        $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );

                if ( !$this->results )
                        return;

                if ( 'all_with_meta' == $this->query_vars['fields'] ) {
                        cache_users( $this->results );

                        $r = array();
                        foreach ( $this->results as $userid )
                                $r[ $userid ] = new WP_User( $userid, '', $this->query_vars['blog_id'] );

                        $this->results = $r;
                }
        }

And finally, the WP_User object is documented here: http://codex.wordpress.org/Class_Reference/WP_User

and defined here: http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/capabilities.php

share|improve this answer
    
Ever tried this link? Linkin is easier than posting :) –  kaiser Aug 25 '11 at 20:18
    
@Kailser The link doesn't work. –  leeand00 Aug 25 '11 at 20:50
    
Sorry - realized it was a bit ridiculous and revised the answer. Also corrected it. It sometimes returns WP_User objects. –  marfarma Aug 25 '11 at 20:57
    
Took the opportunity to update the codex: codex.wordpress.org/Class_Reference/WP_User_Query -- please feel free to improve on my efforts there. –  marfarma Aug 25 '11 at 21:42
    
@marfarma The link works for me and takes you to wp source on wp trac. About the Codex edit: Always rocks when people step in :) –  kaiser Aug 25 '11 at 22:09
add comment

Do the following to the foreach loop:

echo '<pre>';
foreach($author_list as $author)
{
    // author properties:
    // in detail:
    var_dump($author);
    // OR: overview:
    print_r($author);
}
echo '</pre>';
share|improve this answer
add comment

Your Answer

 
discard

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.