diff --git a/src/Tribe/Repositories/Traits/Post_Tickets.php b/src/Tribe/Repositories/Traits/Post_Tickets.php index df9692129e..3497aa077c 100644 --- a/src/Tribe/Repositories/Traits/Post_Tickets.php +++ b/src/Tribe/Repositories/Traits/Post_Tickets.php @@ -243,8 +243,12 @@ public function filter_by_has_tickets( $has_tickets = true ) { $meta_value_compare_clause = $this->ticket_to_post_meta_value_compare( "{$prefix}_ticket_event" ); // Join to the meta that relates tickets to events but exclude RSVP tickets. - $repo->join_clause( "JOIN {$wpdb->postmeta} {$prefix}_ticket_event - ON ({$meta_key_compare_clause}) AND ({$meta_value_compare_clause})" ); + $join_clause = "JOIN {$wpdb->postmeta} {$prefix}_ticket_event ON "; + if ( $meta_key_compare_clause ) { + $join_clause .= "({$meta_key_compare_clause}) AND"; + } + $join_clause .= "({$meta_value_compare_clause})"; + $repo->join_clause( $join_clause ); return; } @@ -351,6 +355,7 @@ public function filter_by_has_rsvp_or_tickets( $has_rsvp_or_tickets = true ) { * @return string The SQL clause to compare meta keys to the ones relating tickets to posts. */ protected function ticket_to_post_meta_key_compare( string $alias, array $allow = null, array $exclude = null ): string { + $meta_keys = []; foreach ( Tickets::modules() as $provider => $name ) { if ( $allow !== null && ! in_array( $provider, $allow, true ) ) { continue; @@ -363,6 +368,10 @@ protected function ticket_to_post_meta_key_compare( string $alias, array $allow $meta_keys[] = tribe( $provider )->get_event_key(); } + if ( empty( $meta_keys ) ) { + return ''; + } + $unprepared = implode( " OR ", array_fill( 0, count( $meta_keys ), "$alias.meta_key = %s" ) ); global $wpdb;