Search code examples
wordpressarchive

WordPress 3.4.1 Showing February as March


So today i wrote the good ol' mod to display my post archive by year, by month and then by post with jquery show/hide functionality and I noticed something rather frustrating.

I'm using the standard code anyone uses for this:

<? $months = $wpdb->get_col("SELECT DISTINCT MONTH(post_date)
    FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'
    AND YEAR(post_date) = '".$year."' ORDER BY post_date DESC");
    foreach($months as $month) :
?>

Now the annoying part... When displaying the months, february appears as march! So the months go January, March, March, April...

I grepped the wordpress files to see if March appeared anywhere where it should say February, but everything was fine. When displaying dates in the post list generated by wp_query, the post list says february as it should, where it should. It's only when using the code above that february displays as march, but shows the february posts, and the second instance of march shows the march posts as it should.

Any know what the heck is goin' on here, and even better, how to fix it???

Edit:

I found it to be this code causing the issue:

<?php echo date( 'F', mktime(0, 0, 0, $month) );?>

I edited the code to this:

<?php echo $month;?>

Now it shows the month NUMBER correctly. How can i get it to show the name?


Solution

  • For all those who face this problem:

    <? $months = $wpdb->get_col("SELECT DISTINCT MONTH(post_date)
        FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'
        AND YEAR(post_date) = '".$year."' ORDER BY post_date DESC");
    
        foreach($months as $month) :
    ?>
    

    then use mktime with all parameters set, and add 1:

    <?php echo date( 'F', mktime(0, 0, 0, $month+1, 0, 0, 0) );?>