Skip to content

Instantly share code, notes, and snippets.

@yratof
Last active December 15, 2015 23:59
Show Gist options
  • Save yratof/5343960 to your computer and use it in GitHub Desktop.
Save yratof/5343960 to your computer and use it in GitHub Desktop.
Show Posts in the Current month - currently, not working like it should do, just shows all dates that are in the future past the current time.
<div class="sixcol first">
<h2>This Month</h2>
<?php
//This gets the current month starting at day 1, and the next month starting at day 1
$now = mktime(0, 0, 0, date("m"), 1, date('Y'));
$then = mktime(0, 0, 0, (date("m") % 12 + 1), 1, date('Y'));
query_posts(
array(
'post_type' => 'member-events', // Custom Post Type
'order' => 'asc', // Order with earliest first
'orderby' => 'wpcf-event-date', // Order by the custom field
'posts_per_page' => -1, // Show all
'meta_key' => 'wpcf-event-date', // Key is the custom field
'meta_value' => array($now, $then), // Array of the current month and next
'meta_compare' => 'BETWEEN') ); // Get posts between now and then
if (have_posts()) : while (have_posts()) : the_post();
$do_not_duplicate = $post->ID; ?>
<?php get_template_part( 'content', 'event' ); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no shows at present.'); ?></p>
<?php endif; wp_reset_query(); ?>
</div>
<div class="sixcol last">
<h2>Next Month</h2>
<?php
$then = mktime(0, 0, 0, (date("m") % 12 + 1), 1, date('Y'));
$later = mktime(0, 0, 0, (date("m") % 12 + 2), 1, date('Y'));
query_posts(
array(
'post_type' => 'member-events',
'order' => 'asc',
'orderby' => 'wpcf-event-date',
'posts_per_page' => -1,
'meta_key' => 'wpcf-event-date',
'meta_value' => array($then, $later),
'meta_compare' => 'BETWEEN') );
if (have_posts()) : while (have_posts()) : the_post();
$do_not_duplicate = $post->ID; ?>
<?php get_template_part( 'content', 'event' ); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no shows at present.'); ?></p>
<?php endif; wp_reset_query(); ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment