• Resolved dieSuse

    (@diesuse)


    Hello,

    I have a simple request for displaying events using a shortcode. I thought it is simple but I cannot manage it. I hope you can start me off.

    I just want to display all already past events from this year. So, I tried to use
    [events_list_grouped mode=”monthly” scope=”2017-01-01,today”] but that doesn’t work.
    Using something like
    [events_list_grouped mode=”monthly” scope=”2017-01-01,2017-05-01″] works, but since I need it as shortcode, because I’d like to see it in the widget area, I cannot get the current date only by using php as I would in the code.

    So, any ideas?

    Thanks in advance,
    Suse

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    you can try to use the shortcode in a text widget and then use another wp plugin to enable shortcode on text widget

    Thread Starter dieSuse

    (@diesuse)

    Hi,

    and thanks for the reply. I think I did not express myself correctly. Since the problem is not the widget but the syntax in the ‘scope’.

    I want to display all past events of this year. So I tried this:

    [events_list_grouped mode=”monthly” scope=”2017-01-01,today”]

    But that doesn’t work. Any other ideas?

    Regards,
    Suse

    Thread Starter dieSuse

    (@diesuse)

    The following link solved my problem: https://wp-events-plugin.com/tutorials/create-your-own-event-scope/

    And if anybody has the same request as I had, here is my code to print past events from a defined date until today:

    // create own scope to show "past events until today"
    add_filter( 'em_events_build_sql_conditions', 'my_em_scope_conditions', 1, 2);
    function my_em_scope_conditions($conditions, $args)
    {	
    	if( !empty($args['scope']) && preg_match('/pastdate-today/', $args['scope']) == 1 )
    	{
    		$my_args = explode(',', $args['scope']);
    		
    		$start_date = date('Y-m-d', strtotime($my_args[1]));		
    		$end_date 	= date('Y-m-d', current_time('timestamp'));
    		$conditions['scope'] = " (event_start_date BETWEEN CAST('$start_date' AS DATE) AND CAST('$end_date' AS DATE)) OR (event_end_date BETWEEN CAST('$end_date' AS DATE) AND CAST('$start_date' AS DATE))";
    	}
    	return $conditions;
    }
    
    add_filter( 'em_get_scopes','my_em_scopes', 1, 1);
    function my_em_scopes($scopes)
    {
    	$my_scopes = array(
    			'pastdate-today' => 'Today and Tomorrow'
    	);
    	return $scopes + $my_scopes;
    }

    The following shortcode prints out all events from 1st of March 2017 until today:

    [events_list_grouped mode=”monthly” scope=”pastdate-today, 2017-03-01″ ]#_EVENTLINK #j.#@_{ – j.}<br />[/events_list_grouped]

    Regards,
    Suse

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Scope of [events_list] for past events’ is closed to new replies.