WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently trying to get my events listing code to print out headers by Month. So basically this:


  • event
  • event


  • event
  • event


Right now it just keeps echoing January. I think it might have something to do with the $currentMonth or the strtotime() but I'm not sure what. Any suggestions? I've been looking at this post to try and figure it out.


    $args = array(
    'post_type' => 'events',
    'orderby' => 'meta_value',
    'meta_key' => 'tf_events_startdate',
    'order' => 'DESC'

    $my_query = new WP_Query($args);

    if ($my_query->have_posts()) : while ($my_query->have_posts()) :

    $custom = get_post_custom(get_the_ID());

    // dates
    $sd = $custom["tf_events_startdate"][0];
    $ed = $custom["tf_events_enddate"][0];

    // - local time format -
    $time_format = get_option('time_format');
    $stime = date($time_format, $sd);
    $etime = date($time_format, $ed);

    // set headers

    if(!isset($currentMonth) || $currentMonth != date("m", strtotime($sd))){
        $currentMonth = date("m", strtotime($sd));

     echo '<h2>'.date("F", strtotime($sd)).'</h2>';


        <strong><a href="<?php the_permalink();?>"><?php the_title();?></a></strong>
         <br />
        <?php // - determine if it's a new day -
        $longdate = date("l, M j, Y", $sd);
        if ($daycheck == null) { echo $longdate; }
        if ($daycheck != $longdate && $daycheck != null) { echo $longdate; } ?>
        <br />
        <?php echo $stime;?>
        <hr />

    <?php endwhile; else: ?>
    <ul id="events">
    <li><?php _e('No Events Yet .'); ?></li>
    <?php endif; ?>
share|improve this question

One thing I noticed: Are $daycheck and $currentMonth defined or initiated previously? Also when you created your custom post type did you make sure 'has_archive' => true, was included? I would go through and echo out all of your variables and see why January keeps coming up. My guess is that it has something to do with $custom["tf_events_startdate"][0] As [0] might be January, [1] February etc.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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