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>
    ";    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么