Viewing 7 replies - 1 through 7 (of 7 total)
  • AdrianV

    (@adrian-verstuyft)

    Hi,

    try the following in your functions.php

    add_filter( 'em_events_build_sql_conditions', 'my_em_scope_conditions',1,2);
    function my_em_scope_conditions2($conditions, $args){
    	if( !empty($args['scope']) && $args['scope']=='last6month' ){
    		$start_date = date('Y-m-d',strtotime("-6 months", current_time('timestamp')));
    		$end_date = date('Y-m-d',strtotime("last day of last month", 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_scopes2($scopes){
    	$my_scopes = array(
    		'last6month' => 'last6month'
    	);
    	return $scopes + $my_scopes;
    }

    then change your scope name from “6-month” to “last6month”

    Thread Starter dhirajrode

    (@dhirajrode)

    Thank you for replay ,
    It’s working for me if I remove the condition to check the scope in the argument array. That is I am not able to pass the argument to the function. Is there other way to pass the scope to the function?

    I am trying to send the scope using code.

    echo EM_Events::output($cell_data['events'],array('format'=>get_option('dbem_full_calendar_event_format'),'scope'=>'last6month'));

    code in function.php

    add_filter( 'em_events_build_sql_conditions', 'my_em_scope_conditions2',1,2);
    
    function my_em_scope_conditions2($conditions, $args){
    
    	if( !empty($args['scope']) && $args['scope']=='last6month' ){
    		$start_date = date('Y-m-d',strtotime("-6 months", current_time('timestamp')));
    		$end_date = date('Y-m-d',strtotime("last day of last month", current_time('timestamp')));
    		$conditions['scope'] = "(event_start_date >= CAST('$start_date' AS DATE))";
    	}
    
    	return $conditions;
    }
    
    add_filter( 'em_get_scopes','my_em_scopes2',1,1);
    function my_em_scopes2($scopes){
    	$my_scopes = array(
    		'last6month' => 'last6month'
    	);
    	return $scopes + $my_scopes;
    }

    Which version of Events Manager are you using?

    Thread Starter dhirajrode

    (@dhirajrode)

    Events Manager Version 5.5.2

    I got this , instead of displaying the events form the last 6 month only. I am displaying the calendar form the last 6 months.

    Is there a link or some code missing from your reply above? I don’t understand what you mean.

    Thread Starter dhirajrode

    (@dhirajrode)

    I have added code to hide the link which we are using to see the previous months in the calendar. I am showing only those links which are less than 6 months from current dates.

    Plugin Support angelo_nwl

    (@angelo_nwl)

    can you try EM 5.5.3 ?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Display past 6 month events in calendar’ is closed to new replies.