Skip to content

Fix for incorrect ticket count in query when running more than on provider. #3594

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions changelog/fix-ticket-preset-ticket-query
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix incorrect ticket counts when using multiple providers on one ticketed post.
7 changes: 4 additions & 3 deletions src/Tribe/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,13 @@ public function get_ticket( $post_id, $ticket_id ) {
/**
* Set the Query args to fetch all the Tickets.
*
* @since 5.5.0 refactored to use the tickets ORM.
* @since 4.6
* @since 5.5.0 refactored to use the tickets ORM.
* @since 4.6
* @since 5.5.2 Set default query args.
* @since 5.8.0 Added the `$context` parameter.
* @since TBD Correct the docblock to reflect the method's behavior.
*
* @param int|WP_Post $post_id Build the args to query only
* @param int $post_id Build the args to query only
* for tickets related to this post ID.
* @param string|null $context The context of the query.
*
Expand Down
10 changes: 9 additions & 1 deletion src/Tribe/Tickets_Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ public function update_start_date( $post_id, $post, $update ) {
$meta_key = $this->key_start_date;
$tickets = $this->get_tickets_ids( $post_id );


foreach ( $tickets as $ticket_id ) {
// Skip tickets with manual updates to that meta
if ( $this->has_manual_update( $ticket_id, $meta_key ) ) {
Expand Down Expand Up @@ -588,8 +589,10 @@ public function get_object_connections( $object ) {
* Gets the Tickets from a Post
*
* @since 4.6
* @since TBD Ensure that if we are querying for more than one ticket provider, the meta query relation is set to OR.
* @since TBD Correct the docblock to reflect the method's behavior.
*
* @param int|WP_Post $post
* @param int $post Which post we are getting the tickets from.
* @return array
*/
public function get_tickets_ids( $post = null ) {
Expand All @@ -615,6 +618,11 @@ public function get_tickets_ids( $post = null ) {
$args['meta_query'] = array_merge( (array) $args['meta_query'], (array) $module_args['meta_query'] );
}

// If we have more than one module (i.e. TC and RSVP), we need to set the relation to "OR" so we get tickets from all of them.
if ( count( $modules ) > 1 ) {
$args['meta_query']['relation'] = 'OR';
}

$query = new WP_Query( $args );

return $query->posts;
Expand Down
Loading