dongxiatuo9827 2015-09-01 12:07
浏览 25
已采纳

如何显示仅在自定义帖子类型中发布的作者列表?

I'm trying to show a list of authors who have posts in a custom post type. What i've done so far is to use the wp_list_authors which only shows the admin posts and doesn't take into account custom posts. What i really want to do is on my Latest news page which has posts from the custom post, 'News' to just show the authors who have posts in that Custom post type.

If anyone could any light to how i can do this then i would be very appreciative :)

Thanks

    <?php
$blogusers = wp_list_authors();
foreach ( $blogusers as $user ) {
    echo "<li><a href='#' data-option-value='.".strtolower($user->user_login)."'><div class='flag'>".get_avatar($user->ID, 'description', true).'</div>' . $user->user_login ."</a></li>
";    }
?>
  • 写回答

1条回答 默认 最新

  • dsh125986083 2015-09-01 12:17
    关注

    I don't think you can do it with this function, but you can do it with direct query, something like

    global $wpdb;
    $authors=$wpdb->get_results('select `'.$wpdb->prefix.'users`.`ID`, `'.$wpdb->prefix.'users`.`user_login`, `'.$wpdb->prefix.'users`.`display_name` from `'.$wpdb->prefix.'users` inner join `'.$wpdb->prefix.'posts` on `'.$wpdb->prefix.'users`.`ID`=`'.$wpdb->prefix.'posts`.`post_author` where `post_type`=\'news\' group by `'.$wpdb->prefix.'users`.`ID`;');
    //you should do a check if $authors is not null and actually got any records returned.
    foreach ( $authors as $user ) 
    {
        echo "<li><a href='#' data-option-value='".strtolower($user->user_login)."'><div class='flag'>".get_avatar($user->ID, 'description', true).'</div>' . $user->display_name."</a></li>
    ";    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题