I asked this question on the WordPress Stack Exchange, and it did not receive most of the answer after 24 hours. So I thought I would bring him to a larger community.
In any case, I am creating an event plugin that works, however I have a slight problem nailing the list page. It shows all the events, but I want them to group them by month. The statement should display the date of the event, capture the month and group entries together that fall out in that particular month. I know this will be foreach, but I'm not sure how to write it.
Here is my loop:
$args = array(
'post_type' => 'events',
'post_status' => 'publish',
'meta_key' => '_eDate',
'orderby' => 'meta_value_num'
);
$the_query = new WP_Query($args);
if ($the_query->have_posts()) :
?>
<div id="event-list">
<?php
global $post;
$month_array = array();
while ($the_query->have_posts()) : $the_query->the_post();
var_dump( get_post_meta( $post->ID, '_eDate', true ) );
$date_field = get_post_meta( $post->ID, '_eDate', true );
$month_format = new DateTime();
$month_format->createFromFormat('Y-m-d', $date_field);
$month_number = $month_format->format('m');
$month_array[] = $month_number;
if ($the_query != 0 && $month_number != $month_array[$the_query->current_post - 1])
echo '<h2>' . $month_format->format( 'F' ) . '</h2>';
?>
<div class="row">
<div class="event-image">
<a href="<?php echo get_permalink(get_the_ID()); ?>">
<?php
if (has_post_thumbnail()) {
the_post_thumbnail('thumbnail');
}
?>
</a>
</div>
<div class="event-content">
<h3><a href="<?php echo get_permalink(get_the_ID()); ?>"><?php the_title(); ?></a></h3>
<div class="event-date"><?php display_event_date(); ?></div>
<div class="event-time"><?php display_event_time(); ?></div>
<div class="event-price"><?php display_event_price(); ?></div>
<br/>
<a href="<?php echo get_permalink(get_the_ID()); ?>" class="event-info">More Information</a>
</div>
<div class="event-buy">
<?php display_event_buy_online_url(); ?>
</div>
</div>
</div>
<?php wp_reset_postdata(); ?>
<?php
endwhile;
endif;
--- EDIT 1 ---
I updated my block of code based on input.
var_dump outputs in this way string(10) "2015-07-09"
I also get two errors.
. WP_Query int C:\xampp\apps\wordpress\htdocs\wp-content\plugins\wp-events-em4b\views\shortcode.php 38
: Undefined offset: -1 C:\xampp\apps\wordpress\htdocs\wp-content\plugins\wp-events-em4b\views\shortcode.php 38
, int , , , , var_dump .