get_results( "SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, COUNT(*) AS count FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY year DESC, month DESC" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery $current_year = 0; foreach ($years as $row) : if ((int) $row->year !== $current_year) : $current_year = (int) $row->year; ?>

month, (int) $row->count)); ?>

    (int) $row->year, 'monthnum' => (int) $row->month, 'posts_per_page' => -1, 'post_status' => 'publish', ]); foreach ($month_posts as $mp) : ?>
  • post_title); ?>