Hey guys, So I’ve been trying to troublshoot this for ages. The Ivory Search on portlandfashioninstitute.com does not work (try to search for “Private Lessons”) But as soon as I remove this script, it works:
/**
* The purpose of this snippet is to filter the event archive (and event taxonomy archive) pages so that they exclude
* events that have tickets no longer on sale.
*
* NOTE: This query is only valid for Event Espresso 4.8+
*
* To Implement this code, add it to the bottom of your themes functions.php file, or add it to a site specific plugin.
*
* @param string $SQL
* @param WP_Query $wp_query
* @return string
*/
function de_ee_tweak_event_list_exclude_ticket_expired_events_where(string $SQL, WP_Query $wp_query): string
{
if (isEspressoEventsArchive($wp_query)) {
$SQL .= ' AND Ticket.TKT_end_date > "' . current_time('mysql', true) . '" AND Ticket.TKT_deleted=0';
}
return $SQL;
}
add_filter(
'posts_where',
'de_ee_tweak_event_list_exclude_ticket_expired_events_where',
15,
2
);
This code prevents Expired Classes from showing up on our pages.
Any idea how I can do both – hide those classes AND get search to work? It’s the same thing no matter which search I use – default or custom plugin. It’s been driving us crazy…
Ok.. Wasn’t 100% sure but here’s what was in the first column after selecting Main Query:
SELECT SQL_CALC_FOUND_ROWS DISTINCT wp_h15xgqan21_posts.ID
FROM wp_h15xgqan21_posts
INNER JOIN wp_h15xgqan21_esp_datetime
ON ( wp_h15xgqan21_posts.ID = wp_h15xgqan21_esp_datetime.EVT_ID )
INNER JOIN wp_h15xgqan21_esp_datetime_ticket AS Datetime_Ticket
ON ( Datetime_Ticket.DTT_ID = wp_h15xgqan21_esp_datetime.DTT_ID )
INNER JOIN wp_h15xgqan21_esp_ticket AS Ticket
ON ( Datetime_Ticket.TKT_ID=Ticket.TKT_ID )
WHERE 1=1
AND ( ((wp_h15xgqan21_posts.post_title REGEXP ‘([[:<:]])private|private([[:>:]])’)
OR (wp_h15xgqan21_posts.post_content REGEXP ‘([[:<:]])private|private([[:>:]])’
AND wp_h15xgqan21_posts.post_password = ”)
OR (wp_h15xgqan21_posts.post_excerpt REGEXP ‘([[:<:]])private|private([[:>:]])’))
AND ((wp_h15xgqan21_posts.post_title REGEXP ‘([[:<:]])lessons|lessons([[:>:]])’)
OR (wp_h15xgqan21_posts.post_content REGEXP ‘([[:<:]])lessons|lessons([[:>:]])’
AND wp_h15xgqan21_posts.post_password = ”)
OR (wp_h15xgqan21_posts.post_excerpt REGEXP ‘([[:<:]])lessons|lessons([[:>:]])’)))
AND wp_h15xgqan21_posts.post_type IN (‘attachment’, ‘e-floating-buttons’, ‘e-landing-page’, ‘espresso_events’, ‘espresso_venues’, ‘instructor’, ‘page’, ‘post’)
AND ((wp_h15xgqan21_posts.post_status = ‘publish’
OR wp_h15xgqan21_posts.post_status = ‘inherit’))
AND Ticket.TKT_end_date > “2024-12-12 22:52:53”
AND Ticket.TKT_deleted=0
ORDER BY wp_h15xgqan21_posts.post_date DESC
LIMIT 0, 10
But whats happening is the function is hooking into the query and adding the SQL to exclude results if there no tickets for that post. On the search query there’s multiple post types so search will ONLY work for EE events with upcoming tickets… any other search will return nothing (becuase nothing else has tickets).
Above the code you posted will be the function:
function isEspressoEventsArchive(WP_Query $wp_query): bool
Note – what should happen with the above is ‘Private Lessons’ (and any other search) should work again, but it does mean that searching will return events with expired tickets.
Great – will the shortcodes begin to show expired classes? Because when I removed the code entirely as a test, all of a sudden all our classes showed up on our pages (even though our short code says Show expired false).
I’m going to try this out and see what happens.
One Last Question – Do you supposed there is any way to wrap expired ticketed classes somehoW? It would be great if those classes when they show up in our search, they had a border with a note saying “currently not being offered” or something>?
Great – will the shortcodes begin to show expired classes?
The above change makes it excludes search queries, so no, the shortcodes should still show as they do now.
Because when I removed the code entirely as a test, all of a sudden all our classes showed up on our pages (even though our short code says Show expired false).
The current code works on the ‘normal’ queries (which includes those used by shortcodes), so removing/disabling the code will show events with expired tickets.
I’m going to try this out and see what happens.
Actually, I’ve just realised! We have this in core now.
Go to Event Espresso -> Events -> Templates.
Set ‘Display Events With Expired Tickets’ to No and save.
Remove the above snippet from the site and see if the event shortcodes show the correct events.
(Side note… Expired events are those where all of the datetimes within the event have expired, events where all of the tickets are expired are different)
One Last Question – Do you supposed there is any way to wrap expired ticketed classes somehoW? It would be great if those classes when they show up in our search, they had a border with a note saying “currently not being offered” or something>?
Interesting idea, not currently but I’ll look into this.