Tribe__Events__Main::get_closest_event_where( string $where_sql,  $query )

Modify the WHERE clause of query when fetching next/prev posts so events with identical times are not excluded

This method ensures that when viewing single events that occur at a given time, other events that occur at the exact same time are are not excluded from the prev/next links


Parameters

$where_sql

(string) (Required) WHERE SQL statement


Top ↑

Return

(string)


Top ↑

Source

File: src/Tribe/Main.php

		public function get_closest_event_where( $where_sql, WP_Query $query ) {
			// If we're here the temporary properties should be set, but let's check and bail if not.
			if ( ! isset( $this->_where_direction, $this->_where_compare, $this->_where_post_id, $this->_where_start_date ) ) {
				return $where_sql;
			}

			// Find out the `postmeta` table alias from the Meta Query; use  the comparison operator to discriminate.
			$meta_query = $query->meta_query;
			$start_date = null;
			foreach ( $meta_query->get_clauses() as $clause ) {
				if ( '_EventStartDate' === $clause['key'] && $this->_where_compare === $clause['compare'] ) {
					$start_date = $clause['alias'];
					break;
				}
			}

			if ( null === $start_date ) {
				// This is weird but some other filtering might be working here, bail.
				return $where_sql;
			}

			global $wpdb;
			/*
			 * If a post has the same date and time as the one we restrict the posts.ID direction.
			 * If the date is the same pick one with a smaller (prev) or bigger (next) posts.ID; if not then
			 * use just the date.
			 */
			$where_sql .= $wpdb->prepare( "\nAND (
					(
						{$start_date}.meta_value = %s
						AND {$wpdb->posts}.ID {$this->_where_direction} {$this->_where_post_id}
					)
					OR
					{$start_date}.meta_value {$this->_where_direction} %s
				)",
				$this->_where_start_date,
				$this->_where_start_date
			);

			return $where_sql;
		}

Top ↑

Changelog

Changelog
Version Description
4.0.2 Introduced.