• Hey,
    I’m trying to add a new scope to present events that were ended two months ago or before. I’ve copied the functions for adding custom scopes from the plugins documentation, edited them a bit, but it just won’t work. I always get the same result when I filter to this scope on the admin side: a list of something like 90% of the events (I have no idea why only 90%), including events from the last two month and future events as well. I have no idea why it’s like that…

    Here is my code:

    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']=='two-months-ago' ){
    		$start_date = date('Y-m-d',strtotime("99 years ago", current_time('timestamp')));
    		$end_date = date('Y-m-d',strtotime("2 months ago", 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(
    		'two-months-ago' => 'Two Months Ago'
    	);
    	return $scopes + $my_scopes;
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    can I know what do you mean by “99 years ago” in the code above?

    Thread Starter ituk

    (@ituk)

    Thank you for the reply,
    About your question – leave that, the code works in the same problematic way even if I change it to “2 years ago” or “3 months ago” or whatever. I get the same issue not matter what I change in the strtotime function.

    In the bottom line, what I want to create is a scope for all events that ended before two months or more.

    Thanks,
    Itamar

    Thread Starter ituk

    (@ituk)

    Angelo?

    Thread Starter ituk

    (@ituk)

    ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding a new scope doesn’t work’ is closed to new replies.