How to limit widget events by date

Home Forums Calendar Products Events Calendar PRO How to limit widget events by date

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1131139
    Ryan Duval
    Participant

    I’m coming back to the same question I asked on an earlier thread here:

    How to make an event 'past' based on start date rather than end date?

    I’m still stuck on how to implement this. Is it possible to pass the results of tribe_get_events() to tribe_get_list_widget_events() like below?

    // Retrieves the posts used in the List Widget loop.
    $posts = tribe_get_list_widget_events( 
       tribe_get_events( array(
          'start_date'   => $today
       ) )
    );

    I only want to see events whose start_date is either today or in the future. I was able to achieve this in our list-view by adding code to list/loop.php which skips any event whose start date doesn’t meet the conditions. But the widget works differently. Any advice on how to achieve this same result with the list widget?

    thanks

    #1131526
    Nico
    Member

    Hi Ryan,

    Thanks for reaching out to us on this!

    Ryan, I believe you could use tribe_get_events() to get the posts you want and then use those posts in the tribe_get_list_widget_events filter.

    Let’s see how to actually do this! Place the code below in your theme (or child theme) functions.php file:


    /* Custom query for event list widget*/
    function tribe_custom_list_widget_events ( ){

    // uncoment the line below and fill in your custom args
    //$args = array( 'start_date' => $today )
    $args = array();

    $posts = tribe_get_events( $args );

    return $posts;
    }

    add_filter( 'tribe_get_list_widget_events', 'tribe_custom_list_widget_events' );

    Other alternative is to modify the query that the widget uses internally with the tribe_events_list_widget_query_args filter. But you should be fine with the above.

    Please let me know if it works for you,
    Best,
    Nico

    #1131720
    Ryan Duval
    Participant

    Hi Nico,
    Thanks for the tip. Unfortunately when I add the following code to my functions.php file,

    function tribe_custom_list_widget_events() {
            $today = date( 'Y-m-d' );
    	$args =  array( 'start_date' => $today ); 
    	$posts = tribe_get_events( array( $args ) );
    	return $posts;	
    } 
    add_filter( 'tribe_get_list_widget_events', 'tribe_custom_list_widget_events' );

    the page in question displays all events- even those that have passed.
    To clarify my setup, I’m using the pro shortcode to display events grouped by tag. For example, one block on the page has:

    [tribe_events_list tags=”IMOD” venue=”yes”]

    The other blocks are similar, just with different tags. But when I enable the code in functions.php it seems to override any of the filters in the shortcode and just shows all events.

    It feels like this should be the right direction because the events are called in pro/widgets/list-widget.php:

    // Retrieves the posts used in the List Widget loop.
    $posts = tribe_get_list_widget_events();

    So logically if tribe_get_list_widget_events(); only returns posts whose start date is after today, it seems like it should work, but for some reason it’s displaying all events… Not sure what I’m doing wrong.

    #1132620
    Nico
    Member

    Thanks for following up Ryan and thanks for clarifying on the context in which you are using the widgets!

    Try this code instead:


    function tribe_custom_widget_args ( $args ) {
    $args['start_date'] = strtotime( 'Y-m-d H:i');
    return $args;
    }

    add_filter( 'tribe_events_list_widget_query_args', 'tribe_custom_widget_args' );

    Please give a try and let me know if it works as expected,
    Best,
    Nico

    #1138723
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘How to limit widget events by date’ is closed to new replies.