Support

Home Forums Event Espresso Premium Shortcode – ESPRESSO_EVENTS

Shortcode – ESPRESSO_EVENTS

Posted: June 4, 2020 at 5:18 am

Viewing 9 reply threads


dee4dogs

June 4, 2020 at 5:18 am

Is there a way with the ESPRESSO_EVENTS shortcode to filter out sold out events?

I can’t see anything here –
https://eventespresso.com/wiki/ee4-shortcodes-template-variables/


Tony

  • Support Staff

June 5, 2020 at 7:31 am

Hi Dee,

We don’t currently have a shortcode parameter for this.

We do have a snippet of code that can do this here:

https://eventespresso.com/topic/ee4-hide-sold-out-events-from-espresso_events-category_slug-page/

That would remove the events from all listings on the site, will that work for you?


dee4dogs

June 10, 2020 at 6:41 am

I’ve had that snippet in a plugin for a few years now (with this modification – https://eventespresso.com/topic/ee4-hide-sold-out-events-from-espresso_events-category_slug-page/#post-160482 ) . It’s working perfectly for the calendar, and the upcoming events widget…. but not for the ESPRESSO_EVENTS shortcode?


Tony

  • Support Staff

June 11, 2020 at 6:58 am

That snippet should apply to the ESPRESSO_EVENTS shortcode.

How are you adding that shortcode to the page? Using a page builder?

Can you post the full snippet you are using so I can test it locally?


dee4dogs

June 11, 2020 at 9:47 am

The shortcode is added using the standard WordPress page editor. No page builders or anything like that. It’s in a Paragraph block by itself.

The HTML view shows:
<p class="has-text-align-center">[ESPRESSO_EVENTS title="Upcoming Online Courses" category_slug=puppyschool-online]</p>

The Snippet is:

/*
REMOVE SOLD OUT & EXPIRED EVENTS FROM THE LISTINGS
*/

/**
 * 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+
 *
 */
function de_ee_tweak_event_list_exclude_ticket_expired_events_where( $SQL, WP_Query $wp_query ) {
	if ( isset( $wp_query->query_vars['post_type'] ) && ( $wp_query->query_vars['post_type'] == 'espresso_events'  || ( is_array( $wp_query->query_vars['post_type'] ) && in_array( 'espresso_events', $wp_query->query_vars['post_type'] ) ) ) && ! $wp_query->is_singular ) {
		$SQL .= ' AND Ticket.TKT_sold < Ticket.TKT_qty AND Ticket.TKT_deleted=0 ';
	}
	return $SQL;
}
add_filter( 'posts_where', 'de_ee_tweak_event_list_exclude_ticket_expired_events_where', 15, 2 );
function de_ee_tweak_event_list_exclude_ticket_expired_events_join( $SQL, $wp_query ) {
	if ( isset( $wp_query->query_vars['post_type'] ) && ( $wp_query->query_vars['post_type'] == 'espresso_events'  || ( is_array( $wp_query->query_vars['post_type'] ) && in_array( 'espresso_events', $wp_query->query_vars['post_type'] ) ) ) && ! $wp_query->is_singular ) {
		if ( ! $wp_query->is_espresso_event_archive && ! $wp_query->is_espresso_event_taxonomy  ) {
			$SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table() . '.ID = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name() . ' ) ';
		}
		$SQL .= ' INNER JOIN ' . EEM_Datetime_Ticket::instance()->table() . ' AS Datetime_Ticket ON ( Datetime_Ticket.DTT_ID=' . EEM_Datetime::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() . ' ) INNER JOIN ' . EEM_Ticket::instance()->table()  . ' AS Ticket ON ( Datetime_Ticket.TKT_ID=Ticket.' . EEM_Ticket::instance()->primary_key_name() . ' ) ';
	}
	return $SQL;
}
add_filter( 'posts_join', 'de_ee_tweak_event_list_exclude_ticket_expired_events_join', 3, 2 );


dee4dogs

June 11, 2020 at 9:50 am

The shortcode displays at the bottom of the front page

https://www.dee4dogs.co.uk/

You’ll see there’s a “Sold Out” event which shouldn’t be visible (and doesn’t appear in the widget or the calendar in the sidebar), and the upcoming Wednesday event which should be displaying.


Tony

  • Support Staff

June 11, 2020 at 3:05 pm

Was there only a single ticket on that event?

Also, does the ‘sold’ value match the limit set on the ticket?

The snippet doesn’t specifically check for an Event Post status, it’s checking the TKT_sold value is less than the TKT_qty value (meaning it’s pulling events where the ticket it’s using aren’t sold out) on a ticket within the event.


Tony

  • Support Staff

June 11, 2020 at 3:05 pm

Note that the snippet works locally for me: https://monosnap.com/file/mVYmHtAUEcow441yQJvwsUEQ2K9iS9

Thats just a page with [ESPRESSO_EVENTS]


dee4dogs

June 12, 2020 at 12:14 am

On that event there were four tickets, only one sold. So the “Sold Out” status was set manually.

So, if I understand correctly, the shortcode is just looking to include for events where tickets are still available…

I was thinking it was displaying all events, and then snippet was excluding sold-out and expired events. This is incorrect.

Is it possible to change the snippet to not display “Sold Out” status events (regardless of ticket sales)?

Thanks for the support.


Tony

  • Support Staff

June 19, 2020 at 7:03 am

It makes the query a little bit odd, but try something like this:

https://gist.github.com/Pebblo/285340c950796e16eae8ba1d2e520513

You would use that function in place of the 2 used previously.

Viewing 9 reply threads

The support post ‘Shortcode – ESPRESSO_EVENTS’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso