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.

I have one page for each author, but if the author doesn't have any posts I can't get its variables, because the loop is empty. The page returns empty, no avatar, no info and stuff, the whole site is empty.

How do I get WordPress to pull out the author variable if there are no posts (what makes no author, but i am on the authors page)..?

I'm using twentyeleven as parent theme.

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

To access the author user object outside of the loop on an author archive, you can do the following:

global $curauth;
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
echo 'This is the author page of '.$curauth->display_name;
share|improve this answer
add comment

I once wrote a Wordpress Plugin called

Show authors without posts

feel free to use it...

share|improve this answer
add comment

You can redirect the 404 back to the author template with this function:

function slug_show_authors_without_posts( $template ) {
    global $wp_query;

    if ( $wp_query->query_vars[ 'post_type' ] === 'author' ) {

        return get_author_template();
    }

    return $template;
}
add_filter( '404_template', 'slug_show_authors_without_posts' );

Here are 2 important things to keep in mind when using this solution: 1) This breaks the template hierarchy's fallback system. So if your theme doesn't have an author.php, you will have a new problem since it will not fallback to index.php like you're used to.

TL;DR You must have a author.php in your theme.

2) This doesn't address the issue that most author.php templates test if the author has posts and if not, returns no post warning. You will need to modify or remove the loop in your author.php to prevent this.

TL;DR Your author.php is probably designed to make this not work. You need to fix this.

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.