Wordpress 在循环中显示用户-即使他们没有帖子
我需要一个普通的循环来显示用户(使用自定义的元字段等),所以我有这个代码来显示一个循环。但我也需要向没有帖子的用户展示Wordpress 在循环中显示用户-即使他们没有帖子,wordpress,loops,Wordpress,Loops,我需要一个普通的循环来显示用户(使用自定义的元字段等),所以我有这个代码来显示一个循环。但我也需要向没有帖子的用户展示 <?php $authors=get_users(); $i=0; //get all users list foreach($authors as $author){ $authorList[$i]['i
<?php
$authors=get_users();
$i=0;
//get all users list
foreach($authors as $author){
$authorList[$i]['id']=$author->data->ID;
$authorList[$i]['name']=$author->data->display_name;
$i++;
}
?>
<ul>
<?php
foreach($authorList as $author){
$args=array(
'showposts'=>1,
'author'=>$author['id'],
'caller_get_posts'=>1
);
$query = new WP_Query($args);
if($query->have_posts() ) {
while ($query->have_posts()){
$query->the_post();
?>
<li>
<h2><?php echo $author['name']; ?></h2>
<a href="<?php echo get_permalink(); ?>"> <?php echo get_the_title(); ?> </a>
</li>
<?php
}
wp_reset_postdata();
}
}
?>
</ul>
-
我现在用“WP\u User\u Query”来做,效果更好。例如: