Support

Home Forums Event Espresso Premium Custom Event Widget Only show current week's events

Custom Event Widget Only show current week's events

Posted: April 10, 2018 at 3:47 pm


Creative Manitoba

April 10, 2018 at 3:47 pm

I have a custom events widget set up and would like to only show the event for the current week (next 7 days) and not show other datetimes for the event.

Is this possible

Thanks


Josh

  • Support Staff

April 11, 2018 at 3:55 pm

Hi Creative Manitoba,

If your custom widget is a copy of the built in Event Espresso Upcoming Events widget, then the following code can be added to a plugin:

function my_custom_event_widget_where_param($where, $category, $show_expired) {
    $where['Datetime.DTT_EVT_start'] = array( '<=', time() + WEEK_IN_SECONDS ); 
    return $where;
}
add_filter(
    'FHEE__EEW_Upcoming_Events__widget__where', 
    'my_custom_event_widget_where_param', 
    10, 
    3
);

The above filter function callback will change the query to limit the events that have datetimes during the next seven days.


Creative Manitoba

April 12, 2018 at 7:11 am

Thanks Josh,

Either it didn’t work or I wasn’t clear enough (my apologies). It is still displaying all the datetimes for the events and I only want the datetime for this week to display. We have courses that run for several weeks and so we’ve created multiple datetimes for each class in a course.

I added the snippet to my functions plugin.

I downloaded the custom widget from a link in a previous forum post on customizing the widget, but I can’t find the link now. It looks like a copy of the original widget.

Here’s the opening few lines of my custom widget:

class EEW_Custom_Upcoming_Events  extends WP_Widget {

	/**
	 * Register widget with WordPress.
	 */
	function __construct() {
		parent::__construct(
			'ee-upcoming-events-widget',
			__( 'Homepage Upcoming Events', 'event_espresso' ),
			 array( 'description' => __( 'A widget to display your upcoming events on the homepage.', 'event_espresso' )),
			array(
				'width' => 300, 
				'height' => 350, 
				'id_base' => 'ee-upcoming-events-widget'
			)
		);
	}

Any help appreciated. Thanks.


Josh

  • Support Staff

April 12, 2018 at 8:46 am

I’m sorry, I forget to mention that you can control the number of datetimes displayed by going to the widget settings. There you can set the number of datetimes to 1.


Creative Manitoba

April 12, 2018 at 9:32 am

Great. That worked. I had an error in a custom espresso_list_of_event_dates function that was causing more than one date to show, but all fixed now. Thanks for all your help.

The support post ‘Custom Event Widget Only show current week's 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.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Creative Manitoba 6 months, 1 week ago ago

Topic Tags

Notifications

This topic is:
pending
Do NOT follow this link or you will be banned from the site!