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

    (@angelo_nwl)

    yes, you can rename the function name and scope name; however, did you created your custom scope?

    Thread Starter robotor

    (@robotor)

    Hello,
    This is my code for the custom scope.

    I am trying to make another custom scope called “thirty-days” which is today + 30.

    /* custom event scope: "this-week" */
    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-week' ){
    		$start_date = date('Y-m-d',current_time('timestamp'));
    		$end_date = date('Y-m-d',strtotime("+7 day", 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(
    		'this-week' => 'This week'
    	);
    	return $scopes + $my_scopes;
    }
    /* END event custom scope: "this-week" */
    Plugin Support angelo_nwl

    (@angelo_nwl)

    hi,

    I see now, you can just duplicate the above function and then change the function name and scope name then change the start_date and end_date as per your requirements.

    Thread Starter robotor

    (@robotor)

    do I need to duplicate the add_filter conditions as well?

    Thread Starter robotor

    (@robotor)

    This is what I’m trying to do, but the new scope is not working. I tried changing the names of more of the things.

    /* custom event scope: "this-week" */
    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-week' ){
    		$start_date = date('Y-m-d',current_time('timestamp'));
    		$end_date = date('Y-m-d',strtotime("+7 day", 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(
    		'this-week' => 'This week'
    	);
    	return $scopes + $my_scopes;
    }
    /* END event custom scope: "this-week" */
    
    /* custom event scope: "thirty-days" */
    add_filter( 'em_events_build_sql_conditions', 'my_em_scope_conditions',1,2);
    function td_scope_conditions($conditions, $args){
    	if( !empty($args['scopetd']) && $args['scopetd']=='thirty-days' ){
    		$start_date = date('Y-m-d',current_time('timestamp'));
    		$end_date = date('Y-m-d',strtotime("+30 day", current_time('timestamp')));
    		$conditions['scopetd'] = " (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( 'td_scopes','td_scopes',1,1);
    function td_scopes($scopestd){
    	$my_scopestd = array(
    		'thirty-days' => 'Thirty days'
    	);
    	return $scopestd + $my_scopestd;
    }
    /* END custom scope: "Thirty days" */

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been damaged by the forum’s parser.]

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to make more than one custom scopes’ is closed to new replies.