I currently have a custom post type called 'events'. I created this from a tutorial here http://tatiyants.com/how-to-use-wordpress-custom-post-types-to-add-events-to-your-site/. I want to query the date to only show the posts with dates coming up and not ones on the past. $event_date >= time
However in the tutorial he displays the results using a shortcode. I am trying to convert this to a standard wp loop so I can display it in my index.php. He uses the following within his shortcode function:
add_shortcode( 'events', 'get_events_shortcode' );
function get_events_shortcode($atts){
global $post;
// get shortcode parameter for daterange (can be "current" or "past")
extract( shortcode_atts( array(
'daterange' => 'current',
), $atts ) );
ob_start();
// prepare to get a list of events sorted by the event date
$args = array(
'post_type' => 'events',
'orderby' => 'event_date',
'meta_key' => 'event_date',
'order' => 'ASC'
);
query_posts( $args );
$events_found = false;
// build up the HTML from the retrieved list of events
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
$event_date = get_post_meta($post->ID, 'event_date', true);
switch ($daterange) {
case "current":
if ($event_date >= time() ) {
echo get_event_container();
$events_found = true;
}
break;
case "past":
if ($event_date < time() ) {
echo get_past_event_summary();
$events_found = true;
}
break;
}
}
}
wp_reset_query();
if (!$events_found) {
echo "<p>no events found.</p>";
}
$output_string = ob_get_contents();
ob_end_clean();
return $output_string;
}
Any help or direction will be greatly appreciated as though I have programmed themes before this is causing me a headache.