0
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 1

0

Instead of the second loop, do the following:

  1. Count the posts per date

  2. 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;
    
    }
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.