• Resolved hughmanwho

    (@hughmanwho)


    I’m trying to make a list of wordpress authors and be able to link to a customized author page for each one from a drop down menu within a plugin.

    In order to do so, I’m trying to use the following code to be able to get all of the author ids and then extract the first names. For some reason I’m getting back some of the data such as display_name, but not information such as user_firstname. This code is modified but very similar to the code found in the wp_list_authors function.

    By itself wp_list_authors does not give me enough freedom and information for what I’m trying to do.

    Any thoughts? Thanks!

    $query_args['orderby'] = 'name';
    $query_args['order'] = 'ASC';
    $query_args['fields'] = 'ids';
    //$query_args['role'] = 'author';
    $query_args['number'] = '';
    $authors = get_users( $query_args );
    
    foreach ( $authors as $author_id )
    {
    	$author = get_userdata( $author_id );
    	echo $author->user_firstname;
    	//print_r($author);
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter hughmanwho

    (@hughmanwho)

    For anyone who stumbles across this with a similar question:

    I’ve discovered that get_userdata doesn’t actually get the meta data.. which is different from what the wordpress codex tells me as of now.

    I believe I have to use get_user_meta() function even though that one doesn’t seem to be working for me either… I’ll keep playing with it.

    GRAQ

    (@graq)

    I’m confused, is this resolved? ??

    If it is, you could post up the answer for anyone else who searches for the same problem. If not, you could post what you have so far?

    Michael

    (@alchymyth)

    @hughmanwho

    i used your exact code and this line:
    echo $author->user_firstname;
    does output the user’s first name.

    this line would do the same:
    echo $author->first_name;

    if you do a var_dump($author); you can see all the info contained in $author.

    do you have any plugins activated which might be interfering with this?

    Thread Starter hughmanwho

    (@hughmanwho)

    @alchymyth

    Which version of WordPress are you using? I’m wondering if they changed something in version 3.1 that broke this?

    I did try print_r($author) to get similiar results, user_firstname and all the other meta data was completely blank.

    @graq

    Sorry, I thought marking it as resolved meant it closed the topic.. I found a work around and went ahead and just used $author->display_name and $author->nice_name even though having the first and last name would still be preferred.

    Don’t know how helpful it will be, but this is what I’m doing for User Meta information:

    $usermeta = get_userdata($user->ID) ;
    echo $usermeta->first_name ;

    In other words, I think you have to do it after you get the ID via get_users.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Why is get_userdata not giving me the first name of my authors?’ is closed to new replies.