0

My list of authors is now based on post count and I would like it to be based on recently active user. My idea was trying changing the orderby to post_date but it has no effect. Any suggestions to how I can do this? The list needs to include user photo.

<!-- users --> 
$allUsers = get_users('orderby=post_count&order=DESC');

$users = array();

foreach($allUsers as $currentUser)
{
    if(!in_array( 'subscriber', $currentUser->roles ))
    {
        $users[] = $currentUser;
    }
}

?>

<section class="content" role="main">
    <?php
        printf('<h1>%s</h1>', the_title());

        foreach($users as $user)
        {
            ?>
            <div class="author">
                <div class="authorAvatar">
                    <?php echo get_avatar( $user->user_email, '128' ); ?>
                </div>
                <div class="authorInfo">
                    <h2 class="authorName"><?php echo $user->display_name; ?></h2>
                    <p class="authorDescrption"><?php echo get_user_meta($user->ID, 'description', true); ?></p>
                    <p class="authorLinks"><a href="<?php echo get_author_posts_url( $user->ID ); ?>">View Author Links</a></p>

                    <p class="socialIcons">
                        <ul>
                            <?php
                                $website = $user->user_url;
                                if($user->user_url != '')
                                {
                                    printf('<li><a href="%s">%s</a></li>', $user->user_url, 'Website');
                                }

                                $twitter = get_user_meta($user->ID, 'twitter_profile', true);
                                if($twitter != '')
                                {
                                    printf('<li><a href="%s">%s</a></li>', $twitter, 'Twitter');
                                }

                                $facebook = get_user_meta($user->ID, 'facebook_profile', true);
                                if($facebook != '')
                                {
                                    printf('<li><a href="%s">%s</a></li>', $facebook, 'Facebook');
                                }

                                $google = get_user_meta($user->ID, 'google_profile', true);
                                if($google != '')
                                {
                                    printf('<li><a href="%s">%s</a></li>', $google, 'Google');
                                }

                                $linkedin = get_user_meta($user->ID, 'linkedin_profile', true);
                                if($linkedin != '')
                                {
                                    printf('<li><a href="%s">%s</a></li>', $linkedin, 'LinkedIn');
                                }
                            ?>
                        </ul>
                    </p>
                </div>
            </div>
            <?php
        }
    ?>
</section>
<!-- usersending --> 
3

I would take a different approach to this using a direct database query to get a list of author IDs ordered by recent posts.

global $wpdb;
$user_ids = $wpdb->get_results(
    "
    SELECT DISTINCT post_author
    FROM $wpdb->posts
    ORDER BY post_date DESC 
    "
);
if ( $user_ids ) {
    foreach ( $user_ids as $user_id ) {
        $user = get_user_by( 'id', $user_id );
        // do stuff with $user
    }
}

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.