Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1041399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:20:50+00:00 2026-05-16T15:20:50+00:00

Within my WP site I have a category called ‘events’ where I am publishing

  • 0

Within my WP site I have a category called ‘events’ where I am publishing event information using two custom fields:

  1. eventdate = human readable event date
  2. eventsortdate = YYYY/MM/DD to list events in the correct order.

I have this bit of code from a helpful post here: http://www.davidrisley.com/events-list-with-wordpress/

<?php
$timecutoff = date("Y-m-d");
$args = array(
'category_name' => 'events',
'orderby' => 'meta_value',
'meta_key' => 'eventsortdate',
'meta_compare' => '>=',
'meta_value' => $timecutoff,
'order' => 'DESC'
);
$my_query = new WP_Query($args);
if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$eventdate = get_post_meta($post->ID, "eventdate", true);
?>
<ul id="events">
<li>
<strong><?php echo $eventdate; ?></strong><br />
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
</li>
</ul>
<?php endwhile; else: ?>
<ul id="events">
<li><?php _e('No Events Scheduled! Stay Tuned.'); ?></li>
</ul>
<?php endif; ?>

This will ensure events are listed in the correct order. However, I would also like to group events by month – so have a header of “month” and group all events which fall into that month display under that title.

Any ideas much appreciated, or alternative suggestions for how to achieve this also much appreciated. Thanks.

EDIT:

Amended code taking into account suggested code:

<?php
$timecutoff = date("Y-m-d");
$args = array(
'category_name' => 'events-press',
'orderby' => 'meta_value',
'meta_key' => 'eventsortdate',
'meta_compare' => '>=',
'meta_value' => $timecutoff,
'order' => 'ASC'
);
$my_query = new WP_Query($args);

if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$eventdate = get_post_meta($post->ID, "eventdate", true);
?>

<?php if(!isset($currentMonth) || $currentMonth != date("m", strtotime($eventdate))){
    $currentMonth = date("m", strtotime($eventdate));
?>
<li><?php echo date("m", strtotime($eventdate)); ?></li>
<?php
}
?>

<ul>
    <li>
        <h5><?php echo $eventdate; ?></h5>
        <h4><?php the_title(); ?></h4>
        <?php the_content(); ?>
    </li>
</ul>
<?php endwhile; else: ?>
<ul id="events">
<li><?php _e('No Events Scheduled! .'); ?></li>
</ul>
<?php endif; ?>

EDIT: further amendment which functions correctly:

<?php
$timecutoff = date("Y-m-d");
$args = array(
'category_name' => 'events-press',
'orderby' => 'meta_value',
'meta_key' => 'eventsortdate',
'meta_compare' => '>=',
'meta_value' => $timecutoff,
'order' => 'ASC'
);
$my_query = new WP_Query($args);

if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$eventdate = get_post_meta($post->ID, "eventdate", true);
$eventsortdate = get_post_meta($post->ID, "eventsortdate", true);
?>

<?php if(!isset($currentMonth) || $currentMonth != date("m", strtotime($eventsortdate))){
    $currentMonth = date("m", strtotime($eventsortdate));
?>
<li><?php echo date("F", strtotime($eventsortdate)); ?></li>
<?php
}
?>

<ul>
    <li>
        <h5><?php echo $eventdate; ?></h5>
        <h4><?php the_title(); ?></h4>
        <?php the_content(); ?>
    </li>
</ul>
<?php endwhile; else: ?>
<ul id="events">
<li><?php _e('No Events Scheduled! .'); ?></li>
</ul>
<?php endif; ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:20:51+00:00Added an answer on May 16, 2026 at 3:20 pm

    You can do amazing things with the WP_Query() function, but I think gruoping doesn’t belongs to it. What you could do is building yourself an array and outputting the results from that array. Or you can just save the current month and output the next month as soon as it changes:

    if(!isset($currentMonth) || $currentMonth != date("m", strtotime($eventdate))){
        $currentMonth = date("m", strtotime($eventdate));
    ?>
    <li><?php echo date("m", strtotime($eventdate)); ?></li>
    <?php
    }
    

    This will print put the month number for the first event ($surrentMonth has not been set, yet) and then again every time a new month is present.

    But for sure you have to change the output (the LI) for what you want it to be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a folder within a site that is a seperate web app than
I have a selection of products within my wordpress site. They are configurable products
I have 4 categories within the 'Default Category' category. Currently by default Magento is
So I have tabbed areas within a site I'm developing, because of my layout
I have been working within another question on this site and have almost completed
I have created an iframe within my site. It loads when I click on
I have a site whose home page shows a single Wordpress category page. I'm
We have a site hosted in IIS6 that we built using the .NET 1.1
I am currently using - http://code.drewwilson.com/entry/autosuggest-jquery-plugin for an autosuggest on my site. I have
Currently building a site in ASP.NET MVC and have to integrate another site within

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.