Tribe__Tickets__Admin__Move_Tickets::exclude_recurring_events( string $where, WP_Query $query )

Excludes Recurring Events from the query taking Custom Tables V1 into account.

This method is a hack to work around the lack of support for the post__not_recurring argument in CT1. Once the post__not_recurring argument is supported in CT1, this method should be removed.


Parameters

$where

(string) (Required) The WHERE clause of the query.

$query

(WP_Query) (Required) The WP_Query instance.


Top ↑

Return

(string) The WHERE clause of the query.


Top ↑

Source

File: src/Tribe/Admin/Move_Tickets.php

	public function exclude_recurring_events( string $where, WP_Query $query ): string {
		if ( ! ( class_exists( ECP::class, false ) && tribe()->getVar( 'ct1_fully_activated' ) ) ) {
			// Either ECP is not active, or CT1 is not fully activated.
			return $where;
		}

		global $wpdb;

		if ( $query instanceof Custom_Tables_Query ) {
			// The query will join on the Occurrences table by default: leverage the `has_recurrence` column.
			$occurrences = Occurrences::table_name( true );
			$where       .= " AND ($occurrences.has_recurrence IS NULL OR $occurrences.has_recurrence = 0)";
		} else {
			/*
			 * The query will likely not join on the Occurrences table and might be a query to fetch `all` post
			 * types, not just Events. In this case, we use a sub-query to exclude from the results:
			 * - Events that have a non-empty '_EventRecurrence' meta value.
			 * - Events that have a non-empty 'post_parent' value.
			 * The sub-query is pretty fast building on the indexed `wp_posts.ID`, `wp_posts.post_type`,
			 * `wp_posts.post_parent` and `wp_postmeta.meta_key` columns; the last comparison happens on
			 * `wp_postmeta.meta_value`, not indexed, but on the smallest possible set of rows.
			 */
			$where .= $wpdb->prepare( " AND $wpdb->posts.ID NOT IN (
				SELECT DISTINCT(p.ID) FROM $wpdb->posts p
				LEFT JOIN $wpdb->postmeta pm ON p.ID = pm.post_id AND pm.meta_key = '_EventRecurrence'
				WHERE p.post_type = %s
				AND ((p.post_parent IS NOT NULL AND p.post_parent != 0)
				OR (pm.meta_value IS NOT NULL AND pm.meta_value != ''))
			)", TEC::POSTTYPE );
		}

		return $where;
	}

Top ↑

Changelog

Changelog
Version Description
5.6.7 Introduced.