Support » Fixing WordPress » Get Archived Posts From Certain Month From All Years

  • I want to display an archive of all posts from each month regardless of the year. I know how to do this for a certain month from one year, but can’t figure out how to do it for all years. I could create tags for each month and then tag the posts by the name of the month that were written in that month, but was hoping for an easier method.

    I then want to create a list of all of the months with links to these archives. So if you visited the archive for January, it would have every post written in January regardless of the year.

    There may be a simple way to do this that I am missing and I have searched the forums and Google and racked my brain, but can’t figure it out.

Viewing 1 replies (of 1 total)
  • You can pass the month value as an argument on your links, like this:

    <a href="">February</a>

    Create a filter for the query in functions.php:

    function mam_posts_where ($where) {
       global $mam_global_where;
       if ($mam_global_where) $where .= " $mam_global_where";
       return $where;
    add_filter('posts_where', 'mam_posts_where');

    And use a query like this in the template for the Page to get the posts:

    $month_to_show = $_GET['month'];
    $mam_global_where = " AND substr($wpdb->posts.post_date, 6, 2) = '$month_to_show' ";
    $my_posts = new WP_Query('posts_per_page=-1&ignore_sticky_posts=1');
    $mam_global_where = '';  // Turn off the filter
    if ($my_posts->have_posts()) {
       while ($my_posts->have_posts()) {
          echo "<p>DATE:$post->post_date MONTH:" . substr($post->post_date, 5,2) . "</p>";
Viewing 1 replies (of 1 total)
  • The topic ‘Get Archived Posts From Certain Month From All Years’ is closed to new replies.