Skip to content

Instantly share code, notes, and snippets.

@rafsuntaskin
Last active August 14, 2023 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafsuntaskin/a89c176d2d8936fe14c2db92fa959234 to your computer and use it in GitHub Desktop.
Save rafsuntaskin/a89c176d2d8936fe14c2db92fa959234 to your computer and use it in GitHub Desktop.
tribe_attendees query
<?php
$tribe_attendees = tribe_attendees('restv1')->where( 'event', $post_id )->where( 'order_status', 'public' )->fields( 'ids' )->all();
?>
//Generated SQL
SELECT
wp_posts.ID
FROM
wp_posts
JOIN wp_postmeta meta_in_1 ON wp_posts.ID = meta_in_1.post_id
LEFT JOIN wp_postmeta order_status_meta ON order_status_meta.post_id = wp_posts.ID
LEFT JOIN wp_posts wc_order_status_post ON wc_order_status_post.ID = order_status_meta.meta_value
LEFT JOIN wp_postmeta edd_order_id ON edd_order_id.post_id = wp_posts.ID
AND edd_order_id.meta_key = '_tribe_eddticket_order'
LEFT JOIN wp_edd_orders edd_order_status ON edd_order_status.id = edd_order_id.meta_value
WHERE
1 = 1
AND wp_posts.post_type IN('tribe_rsvp_attendees', 'tribe_tpp_attendees', 'tec_tc_attendee', 'tribe_eddticket', 'tribe_wooticket')
AND((wp_posts.post_status <> 'trash'
AND wp_posts.post_status <> 'auto-draft'))
AND(meta_in_1.meta_key IN('_tribe_rsvp_event', '_tribe_tpp_event', '_tec_tickets_commerce_event', '_tribe_eddticket_event', '_tribe_wooticket_event')
AND meta_in_1.meta_value IN('1069'))
AND(((order_status_meta.meta_key IN('_tribe_rsvp_status', '_tribe_tpp_status')
AND order_status_meta.meta_value IN('public', 'yes', 'completed', 'wc-completed', 'publish', 'complete'))
OR(order_status_meta.meta_key = '_tribe_wooticket_order'
AND wc_order_status_post.post_status IN('public', 'yes', 'completed', 'wc-completed', 'publish', 'complete'))
OR edd_order_status.status IN('public', 'yes', 'completed', 'wc-completed', 'publish', 'complete')))
GROUP BY
wp_posts.ID
ORDER BY
wp_posts.post_title ASC
// we need to integrate the following OR clause to filter for TC order status, also exclude `tec_tc_attendee` from the previous AND clause.
OR(wp_posts.post_type = 'tec_tc_attendee'
AND wp_posts.post_parent IN(
SELECT
wp_posts.ID FROM wp_posts
WHERE
wp_posts.post_type = 'tec_tc_order'
AND wp_posts.post_status = 'tec-tc-pending')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment