0

In my "About" page I list all WP users of the site. Then in author.php I display the description of the selected user with this code: <?php the_author_meta( 'description' );?>.

Problem: this code only display user description if this user is logged, otherwise it displays nothing. Why?

Code of the "About" page:

<ul>
    <?php
    $blogusers = get_users('orderby=nicename&who=authors');
    foreach ($blogusers as $user) {
        $user_info = get_userdata( $user->ID );
        ?>
        <li>
            <a href="<?php echo get_author_posts_url($user_info->ID); ?>">
                <?php echo $user_info->nickname; ?>
            </a>
        </li>
        <?php
    }
    ?>
</ul>
  • 1
    Your code works fine on my side, logged in or not. Somewhere you have some code/plugin/setting that is causing this behaviour – Pieter Goosen Jun 22 '14 at 20:09
  • 1
    Can you post all code, you've only posted a snippet of the about page code, yet despite having an issue on author.php, you have not shown any of that file – Tom J Nowell Jun 23 '14 at 9:28
3
+25

I have tested your code on my side, and it works perfectly. The relevant info displays, whether I'm logged in or not.

This is definitely not a problem with your code, but more an external problem. You will need to look for any type of code that might restrict this code from showing if a user is logged out, something like if ( is_user_logged_in() ). If you have any type of admin/role type plugin, have a look at those as well. They might be restricting a user from viewing certain pages or info when they are logged out

I would suggest the following, get yourself a code editor like Notepad++ and search your wordpress install for statements like if ( is_user_logged_in() ). Also look at your user roles and what they can and cannot view if you have customized your roles. You should also try to deactivate your plugins one by one and check if the problem goes away or not. Lastly, try one of the bundled themes.

This should at least give you some idea on how to solve your problem

1

You are using "the_author_meta( 'description' )" inside loop or outside loop ? If you are using it outside loop kindly pass user id to id.

<ul>
        <?php
        $blogusers = get_users('orderby=nicename&who=authors');
        foreach ($blogusers as $user) {
            $user_info = get_userdata( $user->ID );
            ?>
            <li>
                <a href="<?php echo get_author_posts_url($user_info->ID); ?>">
                    <?php echo $user_info->nickname; ?>
                    <?php the_author_meta( 'description', $user->ID  );?>
                </a>
            </li>
            <?php
        }
        ?>
    </ul>
0

A shot-in-the-dark, since this is outside my area of expertise -

All of the default themes' author pages have a block like this at the top:

<?php
    /*
     * Queue the first post, that way we know who
     * the author is when we try to get their name,
     * URL, description, avatar, etc.
     *
     * We reset this later so we can run the loop
     * properly with a call to rewind_posts().
     */
    if ( have_posts() )
        the_post();
?>

That (or similar) may be necessary to set up the $authordata global state that get_the_author_meta() relies on when you're not specifying a user ID parameter. (It also may not work if the author hasn't published anything.)

The alternative way as listed on the Author Templates codex page is to fetch the author yourself based on query params

<?php 
    $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name)
                                             : get_userdata(intval($author));
?>

and read properties from that. The other way seems nicer to me, particularly since wp-includes/query ought to do this lookup for us (?), but this might be more universal.

  • I've been downvoted! Did someone try this and it didn't work? Would be interested to hear and learn. – Rup Jun 27 '14 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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