Exclude events from [eab_archive] output by IDs

I'm using the following shortcode
[eab_archive start_end_date="'.$end_date.'" lookahead="1" paged="1" weeks="52" navigation="1" limit="12" template="/page-components/whatsOn--eventCard--archive-shortcode"]
and I'm trying to remove a post from the returned posts. I wondered if there is a way to exclude a post by post id?

  • Adam Czajczyk

    Hello Mike

    I hope you're fine today and thank you for your question!

    There's currently no "out of the box" way to do it but our developers were already asked about it and they are looking if there's any workaround for this. I'm not able yet to tell whether this would require some custom development and/or changes in plugin's core files or if it can be achieved with some additional code snippet but please keep an eye on this ticket and we'll let you know as soon as we got a feedback from our devs.

    Best regards,
    Adam

  • Konstantinos Xenos

    Hi Mike !

    You could try something like this although it's a bit on the 'hacky' side it does the trick.

    In my tests I simply created 3 events ( ev1, ev2 (id 7), ev3 ) and added a simple [eab_archive] shortcode to my Sample Page and removed the "ev2" event.

    This is doable as follows in functions.php:

    function remove_posts_form_eab_archive( $query ) {
    
    	if ( ! $query->is_main_query() && ! is_admin() && 'incsub_event' === $query->query_vars['post_type'] ) {
    		$query->query_vars['post__not_in'] = array( '7' );
    	}
    
    	return $query;
    }
    
    function check_the_current_page() {
    	if ( is_page( 'sample-page' ) ) {
    		add_action( 'pre_get_posts', 'remove_posts_form_eab_archive' );
    	}
    }
    add_action( 'wp_head', 'check_the_current_page' );

    If you have 2x [eab_archive] on the same page though this wouldn't work as it's Page targeted to not mess with the other shortcodes.

    What this does:

    It runs on wp_head and checks if the current page is the 'sample-page' so change is_page( 'sample-page' ) with your page slug that you want this to work with.

    If the page is correct it runs the pre_get_posts to alter the query IF the post_type is of "incsub_event" so everything else on the page should be normal and it removes with "post__not_in" any event IDs, so you should also change $query->query_vars['post__not_in'] = array( '7' ); and add the IDs that you want removed.

    I hope this helps!

    Regards,
    Konstantinos

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.