Support

Home Forums Event Espresso Premium Upcoming Events Widget (4)

Upcoming Events Widget (4)

Posted: January 4, 2017 at 12:41 pm

Viewing 11 reply threads


dee4dogs

January 4, 2017 at 12:41 pm

WP version 4.7
EE version 4.9.24p

Website – http://www.dee4dogs.co.uk

Hi all

So you can see the “Future Courses” (Upcoming Events) widget on the right. That is currently showing “Puppyschool Newhall” an six week course that started on the 22nd December, and is no longer available to purchase tickets for (although there are still datetimes in the future – as the course is still on going. Why is it still showing in the “Upcoming Events” widget?

In that widget I would ONLY like to display events that have the start date in the future AND that are not sold out. I thought that this plugin script below did this? (I don’t speak PHP – I just copy/paste)


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 );

Thank you for your help

  • This topic was modified 7 years, 8 months ago by dee4dogs.
  • This topic was modified 4 years, 8 months ago by Garth.


dee4dogs

January 4, 2017 at 12:43 pm

I’m wondering if this post holds a clue… although I’m a little out of my depth.

https://eventespresso.com/topic/attempting-to-customize-upcoming-events-widget-no-widget-php-available/#post-102681

Thanks


Josh

  • Support Staff

January 4, 2017 at 2:22 pm

Hi there,
There’s actually a simple answer why the Upcoming Events Widget isn’t affected by the code snippet: The Upcoming Events Widget doesn’t interact with WP_Query. The event list pages interact with WP_Query, and the snippet you tried will only affect those.

The other thread that you linked to has instructions on how to make customizations to the Upcoming Events Widget. That’s an older topic, and if you want to make a custom Upcoming Events Widget to show only events that available for registration, you can use this instead:

https://gist.github.com/joshfeck/27a285c4285a6c986053

Then, in the above linked code, the where clause (or $where) would need to be tweaked so the list of events shows only events available to register on.

If you need help with that query, we can dig into that code further.


dee4dogs

January 4, 2017 at 2:43 pm

OK, so I’ve got that github code working, and the “custom” upcoming events widget working.

Your help with the $where query would be great! Thanks.


dee4dogs

January 9, 2017 at 5:07 am

Bump.

Hi guys, I would really appreciate your help to get the widget showing only events available for registration.

THanks.


Josh

  • Support Staff

January 11, 2017 at 12:04 pm

So in your custom widget code, there’s a line of code that sets the where clause that starts with:

$where['Datetime.DTT_EVT_end']

You can change the above to be this instead:

$where['Datetime.Ticket.TKT_end_date']


dee4dogs

January 20, 2017 at 12:58 pm

Legend!! Thanks a million. Works perfectly.


dee4dogs

January 28, 2017 at 11:38 am

Yet another query.

The widget is working great now – only showing future events with tickets.

However, for SOME events it ONLY shows the start time of the first datetime.
For SOME events it shows the start time of the first datetime, and the finish time of the last datetime.

I cannot for the life of me find where this display option is set.
Check the front page and you’ll see what I mean on the right – https://www.dee4dogs.co.uk/

I’ve looked at the options in the Widget control panel.. but they obviously affect ALL events displayed.

The common factor between the events that are showing the END time… is that they’re all at the same venue… I’m gonna do some investigation.


Tony

  • Support Staff

January 31, 2017 at 3:12 am

Hi Dee,

Using this event as an example: https://www.dee4dogs.co.uk/courses/puppy-school-newhall-12/

Since creating that event have you updated it at all? Or did you just create everything in one go and its been setup since?

If you edit the event, make no changes and just save/update then check the widget does it show the correct date range?


dee4dogs

February 3, 2017 at 1:03 pm

Hi Tony,
Sorry for the delayed reply.
So that event you chose as the example is the one that is currently displaying in the Upcoming Events Widget as desired.

I’ve opened & saved the other events, but they’ve not changed.

Typically, events get created in one go. They tend not to be updated, unless there are changes with clients bookings.

Ideally, we’d just like it to show the start date, or the date range… but not the times.

Thank you.
D


Lorenzo Orlando Caum

  • Support Staff

February 5, 2017 at 1:14 pm

Hello,

We have found conditions under which this may happen and are working on some improvements so the dates are always shown.

Those are currently being tested.

We’ll update your support post once they have been released in a maintenance release of Event Espresso.


Lorenzo


Garth

  • Support Staff

February 20, 2017 at 12:35 pm

In 4.9.31.p a fix was added so the widget should show the date range correctly now.

Viewing 11 reply threads

The support post ‘Upcoming Events Widget (4)’ 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