Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/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
尝试使用wp_count_posts获取所有帖子-WordPress PHP数组_Php_Arrays_Wordpress_Function_Attributes - Fatal编程技术网

尝试使用wp_count_posts获取所有帖子-WordPress PHP数组

尝试使用wp_count_posts获取所有帖子-WordPress PHP数组,php,arrays,wordpress,function,attributes,Php,Arrays,Wordpress,Function,Attributes,我正在尝试获取我网站上的作者列表及其全部帖子。 除了循环中的$count\u posts($author->ID)部分之外,所有这些代码都正常工作。 我认为对于get_用户来说,我的阵列也可能存在问题,因为我正在尝试为阵列添加更多部件 function all_authors_list() { $authors = get_users(array( 'role' => 'subscriber', 'orderby' => 'po

我正在尝试获取我网站上的作者列表及其全部帖子。

除了循环中的$count\u posts($author->ID)部分之外,所有这些代码都正常工作。
我认为对于get_用户来说,我的阵列也可能存在问题,因为我正在尝试为阵列添加更多部件

function all_authors_list() {

    $authors = get_users(array(
        'role'      => 'subscriber',
        'orderby'   => 'post_count',
        'order'     => 'DESC',
        'number'    => '20',
        )   
    );

    $authors = $count_posts;
    $count_posts = wp_count_posts('page');
    $published_posts = $count_posts->publish;

    foreach($authors as $author) {
        echo '<div class="author-name">' . $author->first_name . ' ' . $author->last_name . '</div>';
        echo '<div class="author-post-count">' . $count_posts($author->ID) . '</div>';
    }
}
函数所有作者列表(){
$authors=获取用户(数组)(
'角色'=>'订户',
'orderby'=>'post_count',
“订单”=>“描述”,
“编号”=>“20”,
)   
);
$authors=$count_posts;
$count_posts=wp_count_posts('page');
$published\u posts=$count\u posts->publish;
foreach($authors作为$author的作者){
回显“.$author->first_name.”.$author->last_name.”;
回显“.$count_posts($author->ID)。”;
}
}
所以最终输出应该是这样的:
约翰·史密斯
20
帕特里夏·朗
35

…等等。

在post循环中编写以下代码:

<p><?php the_author(); ?> has <?php echo number_format_i18n( get_the_author_posts() ); ?> 
posts</p>
有
职位

参考资料:

您可以使用来实现这一点

基本上,您将把用户ID放入由
$authors
生成的数组中,您可以在
count\u many\u users\u post
中使用该用户ID

函数中有三个参数,您可以使用
$post\u type
参数仅获取页面