Skip to content

Instantly share code, notes, and snippets.

@yratof
Created June 24, 2013 16:32
Show Gist options
  • Save yratof/5851424 to your computer and use it in GitHub Desktop.
Save yratof/5851424 to your computer and use it in GitHub Desktop.
Wordpress loop to list posts by day of the week
<?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' => 'classes', // Custom Post Type
'order' => 'asc', // Order with earliest first
'orderby' => 'wpcf-date-and-time', // Order by the custom field
'posts_per_page' => -1, // Show all
'meta_key' => 'wpcf-date-and-time', // 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; ?>
<h2 itemprop="startDate">
<?php echo(types_render_field("date-and-time", array("format"=>"l","arg2"=>"val2"))); ?>
</h2>
<h3><?php // This should loop through the posts for the date set by the loop above.
$day = types_render_field("date-and-time", array("format"=>"l","arg2"=>"val2"));
$my_query = new WP_Query(
array(
'post_type' => 'classes' // Custom Post Type
)
);
if ( $my_query->have_posts() ) {
while ( $my_query->have_posts() ) {
$my_query->the_post();
the_title();
}
}
wp_reset_postdata();
?></h3>
<?php endwhile; else: ?>
<p>We don't currently have any classes available on this day, but we can <strong>book your child in for a class</strong>, please get in touch to organise this</p>
<?php endif; wp_reset_query(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment