WordPress.org

Forums

[resolved] problem with custom function to display all authors (2 posts)

  1. Boris
    Member
    Posted 6 years ago #

    Hey,

    I've got this function to display all authors of a blog, but for some reason it only ever displays one author, instead of all.

    function display_authors(){
    		global $wpdb;
    		$authors = $wpdb->get_results("SELECT ID, display_name from $wpdb->users ORDER BY user_registered ASC");
    		$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;
    		}
    		foreach( (array) $authors as $author){
    			$posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
    			if($posts != 0) {
    				$author = get_userdata($author->ID);
    				$out =  '<div>';
    				$out .= '<div class="left auth">'. get_avatar($author->user_email, '80') .'</div>';
    				$out .= '<div class="justify"><h3><a href="'. get_author_posts_url($author->ID) .'">'. $author->display_name .'</a></h3>';
    				if(!empty($author->user_description))
    					$out .= $author->user_description;
    				else
    					$out .= _e('The bio of this author will become available soonish...<br />', 'travelmania');
    				$out .= '</div>';
    				$out .= '<p class="postmetadata">';
    				if(!empty($author->user_email))
    					$out .= '<a href="mailto:'.antispambot($author->user_email).'">'.__('Contact the author', 'travelmania').'</a> | ';
    				if($author->user_url != 'http://')
    					$out .= '<a href="'. $author->user_url .'">'. __('Visit the authors website', 'travelmania') .'</a> | ';
    				$out .= __('Published posts: ', 'travelmania') .'<a href="'. get_author_posts_url($author->ID, $author->user_nicename) .'">'. $posts .'</a> | ';
    				$out .= '<a href="'. get_author_feed_link($author->ID) .'">'. __('Author Feed', 'travelmania') .'</a>';
    				$out .= '</p>';
    				$out .= '</div>';
    			}
    		}
    		return $out;
    	}

    Thanks for your help.

  2. Boris
    Member
    Posted 6 years ago #

    Hmm, changed $out = '<div>'; to $out .= '<div>'; and it worked. strange...

Topic Closed

This topic has been closed to new replies.

About this Topic