这是我的代码。我只想显示作者并排除其余的用户角色。请帮忙,我只留下几股头发!!!!
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 ""; } }
答案 0 :(得分: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);