• Resolved Guenni007

    (@guenni007)


    the description of how to create an own event scope leads to my past events of this year:

    add_filter( 'em_events_build_sql_conditions', 'my_em_scope_conditions',1,2);
    function my_em_scope_conditions($conditions, $args){
    	if( !empty($args['scope']) && $args['scope']=='this-year' ){
    		$start_date = date('Y-m-d',strtotime("First day of January", current_time('timestamp')));
    		$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;
    }

    but now i have one event that starts on last year (2018) but ends on the current year.
    i would like to show all past events of the current year but reference day should be the end date – not the start date.

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

    (@angelo_nwl)

    to use event end date, you can replace

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

    with

    $conditions['scope'] = " (event_end_date BETWEEN CAST('$end_date' AS DATE) AND CAST('$start_date' AS DATE))";

    Thread Starter Guenni007

    (@guenni007)

    Thank you – didn’t completely lead to the result I wanted, but your code led to a better understanding of it. Espessially the “event_end_date” option was the crux.
    I had to only replace the first part – not the complete conditions.
    (Sadly i can not show you private content with link to the page – but is is a great difference)

    add_filter( 'em_events_build_sql_conditions', 'my_em_scope_conditions',1,2);
    function my_em_scope_conditions($conditions, $args){
    	if( !empty($args['scope']) && $args['scope']=='this-year' ){
    		$start_date = date('Y-m-d',strtotime("First day of January", current_time('timestamp')));
    		$end_date = date('Y-m-d',current_time('timestamp'));
    		$conditions['scope'] = " (event_end_date BETWEEN CAST('$end_date' AS DATE) AND CAST('$start_date' AS DATE))";
    	}
    	return $conditions;
    }

    don’t know why it is the better way – but it works

    • This reply was modified 5 years, 4 months ago by Guenni007.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘CREATE YOUR OWN EVENT SCOPE’ is closed to new replies.