Support » Plugin: Events Manager » Setting Shortcode to Include Events From Both Today and Future

  • Resolved minnys

    (@minnys)


    Hello,

    I am using Events Manager and am trying to make the events_list shortcode output both events occurring on the current day and events occurring in the future. What should I set the scope attribute to equal so that today’s events and future events are returned by the shortcode?

    I don’t know how to retrieve the current date from WordPress in the regular text editor, so I can’t use the method using two comma-seperated dates for the scope attribute. I have tried using the following shortcodes, and none of them have outputted what I want:

    1. [events_list]
    2. [events_list scope="future"]
    3. [events_list scope="today,future"]
    4. [events_list scope="today&future"]

    I would really like some help finding a solution for my problem, please. I can provide further information as necessary. Thank you!

    This is the link to the Event Manager documentation for shortcodes: http://wp-events-plugin.com/documentation/shortcodes/

    This is the link to the Event Manager documentation for search attributes: http://wp-events-plugin.com/documentation/event-search-attributes/

    I am using WordPress version 5.2.2. and the most recent version of Events Manager. I am developing locally on my Mac using MAMP and Local by Flywheel.

    • This topic was modified 2 years, 2 months ago by minnys. Reason: removed tag
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    at the moment you need custom coding to make this work by creating new event scope to include today and future

    eg. https://wp-events-plugin.com/tutorials/create-your-own-event-scope/

    Setting “current events are past” to “No”, should include today’s event in the future scope, right, @angelo_nwl?

    Thread Starter minnys

    (@minnys)

    Thank you everyone for your help.

    @duisterdenhaag, I already made sure current events are not regarded as past events.

    @angelo_nwl, thank you the link. I could not figure out where to put the PHP code from the article. I tried putting it in a plugin; then I tried saving it as a code snippet using the “Code Snippets” plugin by Shea Bunge. I also tried embedding the PHP (using plugin “PHP Code Widget” by Otto) in the page in which I needed to display the event/s. None of these actions worked. Where do I put the code from the article?

    My solution: I ended up installing “PHP Code Widget” by Otto, which saved the day! After research combined with trial-and-error, I came up with the following code. I put the following code into the PHP code widget, and now it shows events from both today and the future!

    UPDATE: My solution does not work in Safari browser or Firefox Private Windows! Please see my previous bolded text.

    <?php
    
    echo do_shortcode(
    
    '[events_list scope="'. date('Y-m-d', current_time('timestamp')) . ',' . date('Y-m-d', strtotime('+5 months', current_time('timestamp'))) . '" category="featured" limit="1"]
    #_EVENTLINK&nbsp;will take place at #_LOCATIONLINK on #_EVENTDATES from #_EVENTTIMES
    [/events_list]'
    
    );
    ?>
    • This reply was modified 2 years, 2 months ago by minnys.
    Thread Starter minnys

    (@minnys)

    I’m sorry, I posted too soon (rookie mistake). My solution didn’t work in all browsers (such as Safari). I don’t know how to remove the “Resolved” mark from this forum thread, so if a someone could please do that for me it would be much appreciated. So sorry to pester everyone.

    Basically, my question now is: Where do I put the code from the “Create Your Own Event” article? Please see my previous response for details. Thank you!

    Thread Starter minnys

    (@minnys)

    Nevermind, please ignore my previous message. I have resolved the problem. Thank you everyone for putting up with me. My apologies for all these posts. If anyone wants to know my solution to the problem and what my multiple mistakes were, my explanation is as follows.

    I edited the code from the “Create Your Own Event” article and installed it on my site as a WordPress plugin. The first time I created the plugin, being brand new to coding plugins, I just copied and pasted all the code blocks from the article in the order they appeared. That was the first thing I did wrong. I realize now that the following line of PHP was only supposed to appear once in the plugin file:
    $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))";

    To understand my second mistake, you need to see the following chunk of code I used:

    add_filter( 'em_get_scopes','my_em_scopes',1,1);
    function my_em_scopes($scopes){
        $my_scopes = array(
            'today-future' => 'Today and Future'
        );
        return $scopes + $my_scopes;
    }

    When I tried to use the new scope in a shortcode, I set the scope attribute to ‘Today and Future’. I understand now that I needed to set the scope attribute to ‘today-future’. When I set the scope attribute to ‘today-future’, the shortcode worked in other browsers.

    The reason my solution from two posts ago did not work in other browsers was because some browsers apparently aren’t compatible with the PHP Code Widget by Otto.

    Following is the full plugin code I am using now (except for the plugin header). Most of the code I copied and pasted from the “Create Your Own Event Scope” article:

    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']=='today-future' ){
            $start_date = date('Y-m-d',current_time('timestamp'));
            $end_date = date('Y-m-d',strtotime("+12 months", 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(
            'today-future' => 'Today and Future'
        );
        return $scopes + $my_scopes;
    }
    • This reply was modified 2 years, 2 months ago by minnys.
    Stephan Mönninghoff

    (@stephanmoenninghoff)

    I was trying to do the same because users were complaining that the event they are attending is not visible on the day, although it contains venue information and miscellaneous other bits that are useful on the actual day the event takes place.

    Is this really that complicated? Do I need to use code snippets to get this to work? No problem if it is, then I’ll bite the bullet but before I do: where do you find the “current events are past” to “No” setting, @duisterdenhaag?

    Ok, I can confirm setting Setting “current events are past” to “No” works perfectly.

    Thread Starter minnys

    (@minnys)

    Thank you. I have successfully done this as well. The issue is fully resolved. Either I was selecting the wrong setting or an update of the plugin has fixed it. Thank you for putting up with me!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Setting Shortcode to Include Events From Both Today and Future’ is closed to new replies.