Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix $meta_keys notice error and MySQL syntax error. #2926

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Tribe/Repositories/Traits/Post_Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading