User Meta Data on Author Page

Permalink /author/steve-olaff uses the theme file author.php unless a more specific template is found.

Author.php includes a variable $author that holds the user ID of the author so the user data and meta data can be accessed using:

$curmem = get_user_meta(intval($author));

where $curmem is an array so data can be accessed using for instance:

echo $curmem->[user_description][0];

This is because the array $curmem looks like:

[first_name] => Array ( [0] => Peter )

or you can get a single piece of data using

$user_last = get_user_meta( $user_id, $key, $single );

where $user_id is an integer, $key is the array key and $single = true returns the value, false returns as array as above. eg

$user_last = get_user_meta( 9, 'last_name', true );

Would return ‘olaff’.

This coupled with custom user meta data can be used to generate a nice user profile page.

Leave a Comment