admin管理员组文章数量:1122846
function test_dashboard_content() {
$args = array( 'posts_per_page' => -1, 'post_type' => array( 'post', 'page' ),
'post_status' => 'publish', 'date_query' => array( 'after' => '1 year ago' ) );
$posts = get_posts( $args );
$testlist = '';
foreach ( $posts as $post ) {
$testlist .= '{date: "' . get_the_date( 'Y-n-j', $post ) . '", value: "1"},';
}
}
Right now, the value (value: "1"
) is simply hard-coded as 1
, but how would I collect the total post count for each respective get_the_date
instead in this context?
function test_dashboard_content() {
$args = array( 'posts_per_page' => -1, 'post_type' => array( 'post', 'page' ),
'post_status' => 'publish', 'date_query' => array( 'after' => '1 year ago' ) );
$posts = get_posts( $args );
$testlist = '';
foreach ( $posts as $post ) {
$testlist .= '{date: "' . get_the_date( 'Y-n-j', $post ) . '", value: "1"},';
}
}
Right now, the value (value: "1"
) is simply hard-coded as 1
, but how would I collect the total post count for each respective get_the_date
instead in this context?
1 Answer
Reset to default 0Instead of the second loop, do the following:
Count the posts per date
Display them as you will
// Count the posts per date $count = []; foreach ( $posts as $post ) { $date = get_the_date( 'Y-n-j', $post ); $count[ $date ] = ! isset( $count[ $date ] ) ? 1 : $count[ $date ] + 1; }
本文标签: loopHow to get total posts count for each date
版权声明:本文标题:loop - How to get total posts count for each date? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305112a1932476.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论