Wordpress 列出作者

Wordpress 列出作者,wordpress,themes,Wordpress,Themes,我希望wordpress给我一个包含所有作者的数组。有一些愚蠢的函数,它们回显html(wp_list_authors())——但这不是我想要的 我想获得完整的配置文件(ID、名称、元数据) 我目前的方法不是,我正在寻找的——确切地说,是**它 $authors = wp_list_authors(array( 'optioncount' => false, 'exclude_admin' => false, 'show_fullname' => false, 'hid

我希望wordpress给我一个包含所有作者的数组。有一些愚蠢的函数,它们回显html(wp_list_authors())——但这不是我想要的

我想获得完整的配置文件(ID、名称、元数据)

我目前的方法不是,我正在寻找的——确切地说,是**它

$authors = wp_list_authors(array(
'optioncount'   => false, 
'exclude_admin' => false, 
'show_fullname' => false,
'hide_empty'    => false,
'echo'          => false,
'html'      => false)
);
$authors = explode(", ", $authors);
即使在这里,我也被困住了,因为没有通过名称()或类似的方式获取作者id


请帮助,我不想在一个该死的模板中执行SQL。

好吧,如果你知道用户ID,你可以使用

否则,你应该看看这个建议:


这将给出$authorsInfo数组中每个用户的信息(包括WP扩展信息)。如果需要按用户的角色(“作者”)获取用户,则应使用WP\u User\u搜索类。您在这里几乎被迫使用SQL,这并没有什么错。

您最好使用
get\u users
,它在中。

如果有人仍在查看,这就是以正确的方式返回数组中的作者的方法

function get_all_authors() {
global $wpdb;

foreach ( $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 = get_userdata( $row->post_author );
    $authors[$row->post_author]['name'] = $author->display_name;
    $authors[$row->post_author]['post_count'] = $row->count;
    $authors[$row->post_author]['posts_url'] = get_author_posts_url( $author->ID, $author->user_nicename );
endforeach;

return $authors;
}
返回的数组(
$authors
)包含用户ID作为键,还包含作者链接、文章计数及其名称。当然,在您的主题视图中,您可以将
get_all_authors()
设置为一个变量,并根据需要循环使用它


希望这有帮助

在我看来,这不是一种好的风格,但是威尔。。无论如何^.^谢谢。如果有人使用上述代码,我会尝试一下:确保使用“$authorId->ID”而不是“$authorId”来获取用户数据。wordpress几乎没有“请在没有愚蠢格式的情况下给我数据”类型函数,这让我很吃惊。你认为得到一份作者名单很容易吗?布拉格!!!!非常感谢!
function get_all_authors() {
global $wpdb;

foreach ( $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 = get_userdata( $row->post_author );
    $authors[$row->post_author]['name'] = $author->display_name;
    $authors[$row->post_author]['post_count'] = $row->count;
    $authors[$row->post_author]['posts_url'] = get_author_posts_url( $author->ID, $author->user_nicename );
endforeach;

return $authors;
}