• Resolved joncwhall

    (@joncwhall)


    Hi,

    I have a reports page on my site that, amongst other things, shows everyone who booked an event in the last week.

    [events_list scope=”2018-01-22,2018-01-27″]#_ATTENDEESLIST[/events_list]

    Each week I have to go in and change the dates. Is there any way I can insert a relative date type thing (ie: between ‘7 days ago’ and ‘1 day ago’) into the ‘scope’ to save having to do this?

    Thanks,

    Jon

Viewing 1 replies (of 1 total)
  • Hi,

    I needed to do this and had to create a custom scope as detailed in the events manager documentation: http://wp-events-plugin.com/tutorials/create-your-own-event-scope/. I’m not a coder so it took me a while to understand this and adapt it several times. I’ve included one of mine below and my simplistic explanation of how it works as unless you’re a coder, the documentation explanation isn’t that great. My scope gets a week’s worth of events from the coming Saturday. Compare this to the documentation’s example of getting events for today and tomorrow and you’ll get an idea of what you need to do.

    To create a custom scope you need to edit functions.php (make a backup of it first in case) and then paste in these two add_filters:

    add_filter( ’em_events_build_sql_conditions’, ‘my_em_Saturday_to_Saturday_scope_conditions’,1,2);
    function my_em_Saturday_to_Saturday_scope_conditions($conditions, $args){
    if( !empty($args[‘scope’]) && $args[‘scope’]==’saturday-to-saturday-events’ ){
    $start_date = date(‘Y-m-d’, strtotime(“this saturday”));
    $end_date = date(‘Y-m-d’, strtotime(“this saturday + 7 days”));
    $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’,’saturday_to_saturday_em_scopes’,1,1);
    function saturday_to_saturday_em_scopes($scopes){
    $saturday_to_saturday_scopes = array(
    ‘saturday-to-saturday-events’ => ‘Week from Saturday events’
    );
    return $scopes + $saturday_to_saturday_scopes;
    }

    The first add_filter defines the custom scope itself. The second add_filter then registers the custom scope with events manager by adding it to the list of defined scopes.

    In the first add_filter I define a function called my_em_Saturday_to_Saturday_scope_conditions. You should change every occurrence of this to a name of your choice (e.g. in the add_filter line as well). The function looks to see if the scope’s “internal” name used in the event list shortcode is called saturday-to-saturday-events. Again you should change this to a name of your choice (you’ll use this name in the second add_filter too). If the scope name matches, then the start date is calculated as the date of this coming Saturday and the end date is calculated by adding 7 days onto the date of this Saturday. You need to change these to reflect your requirements – google ‘php strtotime’ and you will see that there is a whole range of text strings it can use to calculate a date. The function then uses the two dates to query the database to retrieve events.

    In the second add_filter, a function saturday_to_saturday_em_scopes is created. You should change every occurrence of this to a name of your choice (e.g. again in add_filter line). An array variable $saturday_to_saturday_scopes is created (change its name again everywhere) which holds the “internal” name of the scope (saturday-to-saturday-events) and also the name for the scope that you see in drop down scope lists (Week from Saturday events). Change both of these names making sure that the internal name you use is the same as the one you used in the first add_filter after [‘scope’]==.
    Finally, the custom scope is appended to the list of scopes in event mamanger.

    Then to use the new scope, simply [events_list scope=’internal name you used’ …]

    Try it on a test site and hopefully you’ll develop what you need.

Viewing 1 replies (of 1 total)

The topic ‘events_list relative scope?’ is closed to new replies.