Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 在循环中显示用户-即使他们没有帖子_Wordpress_Loops - Fatal编程技术网

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”来做,效果更好。例如: