0

这是我的代码。我只想显示作者并排除其余用户角色。请帮忙,我只剩下几根头发了!!!!

function contributors() { global $wpdb;

$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name");

foreach($authors as $author) 
{ 
echo "< li >"; 
echo "< a href=\"".get_bloginfo('url')."/?author="; 
echo $author->ID; echo "\">"; 
echo get_avatar($author->ID, 125); 
echo ""; 
echo ''; 
echo "< a href=\"".get_bloginfo('url')."/?author="; 
echo $author->ID; 
echo "\">"; the_author_meta('display_name', $author->ID); 
echo ""; 
echo ""; 
echo ""; } }
4

1 回答 1

0

由于我不知道 wordpress 如何或在何处存储用户角色,我建议这样使用get_role()

$realUser = wp_get_current_user();
foreach($authors as $author) {
    set_current_user($author->ID);
    if (get_role() != $authorRole) continue;
    set_current_user($realUser->ID);
    // ...
}
set_current_user($realUser->ID);
于 2010-12-20T01:35:26.147 回答