/** * Call this function in a template to query the events and start the loop. Do not * subsequently call the_post() in your template, as this will start the loop twice and then * you're in trouble. * * http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query#Query_based_on_Custom_Field_and_Category * * @param int number of results to display for upcoming or past modes (default 10) * @param string category name to pull events from, defaults to the currently displayed category * @uses $wpdb * @uses $wp_query * @return array results */ function get_events($numResults = null, $catName = null) { if (!$numResults) { $numResults = get_option('posts_per_page', 10); } global $wpdb, $spEvents; $spEvents->setOptions(); if ($catName) { $categoryId = get_cat_id($catName); } else { $categoryId = get_query_var('cat'); } $extraSelectClause = ''; $extraJoinEndDate = ''; if (events_displaying_month()) { $extraSelectClause = ", d2.meta_value as EventEndDate "; $extraJoinEndDate = " LEFT JOIN {$wpdb->postmeta} as d2 ON({$wpdb->posts}.ID = d2.post_id) "; $whereClause = " AND d1.meta_key = '_EventStartDate' AND d2.meta_key = '_EventEndDate' "; // does this event start in this month? $whereClause .= " AND ((d1.meta_value >= '" . $spEvents->date . "' AND d1.meta_value < '" . $spEvents->nextMonth($spEvents->date) . "') "; // Or does it end in this month? $whereClause .= " OR (d2.meta_value >= '" . $spEvents->date . "' AND d2.meta_value < '" . $spEvents->nextMonth($spEvents->date) . "' ) "; // Or does the event start sometime in the past and end sometime in the distant future? $whereClause .= " OR (d1.meta_value <= '" . $spEvents->date . "' AND d2.meta_value > '" . $spEvents->nextMonth($spEvents->date) . "' ) ) "; $numResults = 999999999; } if (events_displaying_upcoming()) { $extraSelectClause = ", d2.meta_value as EventEndDate "; $extraJoinEndDate = " LEFT JOIN {$wpdb->postmeta} as d2 ON({$wpdb->posts}.ID = d2.post_id) "; $whereClause = " AND d1.meta_key = '_EventStartDate' AND d2.meta_key = '_EventEndDate' "; // Is the start date in the future? $whereClause .= ' AND ( d1.meta_value > "' . $spEvents->date . '" '; // Or is the start date in the past but the end date in the future? (the event is currently ongoing) $whereClause .= ' OR ( d1.meta_value < "' . $spEvents->date . '" AND d2.meta_value > "' . $spEvents->date . '" ) ) '; } $eventsQuery = "\n\t\t\tSELECT {$wpdb->posts}.*, d1.meta_value as EventStartDate\n\t\t\t\t{$extraSelectClause}\n\t\t\t \tFROM {$wpdb->posts} \n\t\t\tLEFT JOIN {$wpdb->postmeta} as d1 ON({$wpdb->posts}.ID = d1.post_id)\n\t\t\t{$extraJoinEndDate}\n\t\t\tLEFT JOIN {$wpdb->term_relationships} ON({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)\n\t\t\tLEFT JOIN {$wpdb->term_taxonomy} ON({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id)\n\t\t\tWHERE {$wpdb->term_taxonomy}.term_id = {$categoryId}\n\t\t\tAND {$wpdb->term_taxonomy}.taxonomy = 'category'\n\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\t{$whereClause}\n\t\t\tORDER BY d1.meta_value " . $spEvents->order . "\n\t\t\tLIMIT {$numResults}"; $return = $wpdb->get_results($eventsQuery, OBJECT); return $return; }
?> </span></a> <?php } elseif (events_displaying_past() && get_next_posts_link()) { ?> <?php next_posts_link('<span>« Previous Events</span>'); ?> <?php } ?> </div> <div class="tec-nav-next"><?php // Display Next Page Navigation if (events_displaying_upcoming() && get_next_posts_link()) { ?> <?php next_posts_link('<span>Next Events »</span>'); ?> <?php } elseif (events_displaying_past() && get_previous_posts_link()) { ?> <?php previous_posts_link('<span>Next Events »</span>'); // a little confusing but in 'past view' to see newer events you want the previous page ?> <?php } elseif (events_displaying_past() && !get_previous_posts_link()) { ?> <a href='<?php
/** * where filter for standard wordpress templates. Inspects the event options and filters * event posts for upcoming or past event loops * * @param string where clause * @return string modified where clause */ public function events_search_where($where) { if (!$this->in_event_category()) { return $where; } $where .= ' AND ( eventStart.meta_key = "_EventStartDate" AND eventEnd.meta_key = "_EventEndDate" ) '; if (events_displaying_month()) { } if (events_displaying_upcoming()) { // Is the start date in the future? $where .= ' AND ( eventStart.meta_value > "' . $this->date . '" '; // Or is the start date in the past but the end date in the future? (meaning the event is currently ongoing) $where .= ' OR ( eventStart.meta_value < "' . $this->date . '" AND eventEnd.meta_value > "' . $this->date . '" ) ) '; } if (events_displaying_past()) { // Is the start date in the past? $where .= ' AND eventStart.meta_value < "' . $this->date . '" '; } return $where; }