• Resolved fondalashay

    (@fondalashay)


    Hello!

    I am working on a author page that will list my authors along with some info on them. Tho code is partially working. The problem is now that i have 5 “users” and it recognizes that – but it adds the profile of the admin 5 times instead.

    <?php
    
    // Get the authors from the database ordered by user nicename
    global $wpdb;
    $query = "SELECT ID, user_nicename from $wpdb->users ORDER BY user_nicename";
    $author_ids = $wpdb->get_results($query);
    
    // Loop through each author
    foreach($author_ids as $author) :
    
    // Get user data
    $curauth = get_userdata($author->ID);
    
    // Get link to author page
    $user_link = get_author_posts_url($curauth->ID);
    
    // Set default avatar (values = default, wavatar, identicon, monsterid)
    $avatar = 'wavatar';
    ?>
    
    <?php wp_list_authors ?>
    <small style="visibility:hidden; font-size:1px;">Line Break</small>
    <?php echo get_avatar( get_the_author_email(), '50' ); ?>
    <p><b><?php the_author_link(); ?></b> <small>(<?php the_author_posts(); ?> Articles)</small></p>
    <p><?php the_author_description(); ?></p>
    
    <?php endforeach; ?>

    Any help would be greatly appreciated!!

Viewing 3 replies - 16 through 18 (of 18 total)
  • MichaelH

    (@michaelh)

    wp_list_authors is a hell of a lot slower then get_users_of_blog.. ??

    Is that right t31os_?

    Yes, i’d imagine it’s related to the queries used by wp_list_authors ..
    wp-includes/author-template.php: Lines 259 – 265

    /** @todo Move select to get_authors(). */
    	$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
    
    	$author_count = array();
    	foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row) {
    		$author_count[$row->post_author] = $row->count;
    	}

    Looks like a loop of queries, so essentially several queries, compare that to the get_users_of_blog query..
    wp-includes/user.php: Line 281

    $users = $wpdb->get_results( "SELECT user_id, user_id AS ID, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$wpdb->prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" );

    1 query, so less extensive..

    I’m sorry to post here, but I can’t think of anywhere better!

    The code at https://wordpress.pastebin.ca/1656804 works great – but what I’d like to do is to actually list the posts of each author, not just the number of posts.

    Also – is there a way to exclude the admins from the query, or to specify a user ID to omit?

    Thanks!

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘List authors is listing admin multiple times’ is closed to new replies.