• Hi,

    On a single event page I want to show the next 3 events at the bottom. However, I don’t want the current event to be shown. Is there an option to exclude that with the shortcode?

    Something like: exclude=”this”

    My shortcode now:

    [events_list scope=”future” category=”tentoonstellingen” limit=”3″][/events_list]

Viewing 11 replies - 1 through 11 (of 11 total)
  • [events_list scope=”future” category=”tentoonstellingen” offset=1 limit=”3″][/events_list]

    Hi @pjmorgan622, I don’t think that’s what @henkendehenk wants. He wants to put the events_list on the single event pages and exclude the single event that is displayed on that page. So, the event to be excluded will be different depending on which single event page it’s displayed on.

    Thread Starter henkendehenk

    (@henkendehenk)

    Hi @joneiseman , That`s exactly what i want. 😉

    First you would need to add the following code snippet to support excluding an event:

    add_filter( 'em_events_output_events', function( $events, $events_count, $args ) {
    if ( !empty( $args['exclude'] ) && is_numeric( $args['exclude'] ) ) {
    $new_events = [];
    foreach ( $events as $event ) {
    if ( $event->event_id != $args['exclude'] ) {
    $new_events[] = $event;
    }
    }
    return $new_events;
    }
    return $events;
    }, 10, 3 );

    You can add this code snippet using the Code Snippets plugin.

    Then create the directory wp-content/plugin-templates/events-manager/templates/ then copy the file wp-content/plugins/events-manager/templates/templates/event-single.php to that directory then modify the copied file. Add the following at the bottom of the file just above the last </div> tag.

    <?php
    do_shortcode('[events_list scope=future category=tentoonstellingen exclude=' . $EM_Event->event_id . ' limit=4][/events_list]');
    ?>
    Thread Starter henkendehenk

    (@henkendehenk)

    @joneiseman Thanks for helping to find a solution.
    I have the shortcode in a Raw HTML element in the WPBakery Pagebuilder. Because the page builder gives me more options to arrange the event page as I wish.

    I tried to map the php code into a new shortcode with the following functions.php code;

    add_shortcode( ‘tentooneventsblokken’, ‘tentoonevent’ );
    function tentoonevent() {
    $shorttentoon = do_shortcode(‘[events_list scope=future category=tentoonstellingen limit=4 exclude=’.$EM_Event->event_id.’]html items[/events_list]’);
    return $shorttentoon;
    }

    But it doesn`t seem to work, as i see 4 events with the current event.

    Are you using a shortcode to display the single event in WPBakery Pagebuilder?

    Thread Starter henkendehenk

    (@henkendehenk)

    No, I use the pagebuilder to lay out the content of the event. This content includes the shortcode to show 3 other events.

    I tested it out and the exclude parameter works fine once I added the code snippet to support it. In the events_list shortcode you would use something like exclude=351 (were 351 is equal to the event id). I’m not sure if the $EM_Event global variable is available on your WPBakery page. But if it is the following shortcode would work:

    add_shortcode( 'tentooneventsblokken', 'tentoonevent' );
    function tentoonevent() {
    global $EM_Event;
    return do_shortcode('[events_list scope=future category=tentoonstellingen limit=4 exclude='.$EM_Event->event_id.']html items[/events_list]');
    }
    • This reply was modified 1 month, 2 weeks ago by joneiseman.

    You need to be able to get either the post_id or the event_id. You could try using get_the_ID().

    add_shortcode( ‘tentooneventsblokken’, ‘tentoonevent’ );
    function tentoonevent() {
    $event_id = em_get_event(get_the_ID(), 'post_id');
    return do_shortcode('[events_list scope=future category=tentoonstellingen limit=4 exclude='.$event_id.’]html items[/events_list]');
    }

    This won’t work if you don’t have access to either the $EM_Event or the $post.

    Thread Starter henkendehenk

    (@henkendehenk)

    @joneiseman both options doesn`t seem to work.
    The post_id option gives a fatal error on the single event page.
    The EM_events option returns 4 events with the current (also with the option exclude=77)

    Here is a screenshot of the settings.

    Without having a better understanding of how WPBakery Page builder is generating the HTML, I won’t be able to help you.

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.