• Resolved pracko

    (@pracko)


    I have my events set (via functions.php) to show in my blog feed. Once the event has passed, the Event is then categorized as ‘expired-event’. I’d like for all such categorized events to not be visible in my blog feed anymore. How can I do this via the functions.php file?

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

    (@angelo_nwl)

    just to confirm, did you mean exclude specific event per category?

    Thread Starter pracko

    (@pracko)

    Yes as in all events with the category name “foo” for example.

    Plugin Support angelo_nwl

    (@angelo_nwl)

    If you are using events listing shortcode, you can try something like [events_list category=”-X”] where X is the events category id and negative ( – ) means exclude.

    https://wp-events-plugin.com/documentation/shortcodes/
    https://wp-events-plugin.com/documentation/event-search-attributes/

    Thread Starter pracko

    (@pracko)

    Angelo,

    No I am NOT using a shortcode to display events in my main blog feed, I am using the following in functions.php:

    /** Add Event CPT to Blog Feed **/
    add_filter( 'pre_get_posts', 'my_get_posts' );
    function my_get_posts( $query ) {
    	if ( ( is_home() && $query->is_main_query() ) || is_feed() )
    		$query->set( 'post_type', array( 'post', 'event' ) );
    	return $query;
    }

    Thus, I need a filter to exclude events that have a specific event category from appearing in the blog feed.

    Example: When an event has passed, I change the event category from ‘active’ to ‘expired’. I need a filter so that all events assigned the category name ‘expired’ will not show in the blog feed anymore.

    Thanks

    Plugin Support angelo_nwl

    (@angelo_nwl)

    this might not work out of the box, however, it should give a good start

    
    <?PHP 
    
    $args = array(
            'posts_per_page' => 3,
            'post_type' => 'event',
            'orderby' => 'menu_order',
            'order' => 'ASC',
            'tax_query' => array(
    		array(
    			'taxonomy' => 'event-categories',
    			'field'    => 'slug',
    			'terms'    => 'events',
    		),
    	),
        );
        $the_query = new WP_Query( $args ); 
    
    ?>
    
    Stonehenge Creations

    (@duisterdenhaag)

    HI @pracko,
    EM user here too 🙂

    It would be much easier to use the shortcode, like Angelo suggested. Then you can easily use the Event Search Arguments (https://wp-events-plugin.com/documentation/event-search-attributes/)

    [events_list scope="future" category="-1"]

    PHP version:
    do_shortcode('[events_list scope="future" category="-1"]');

    “Future” will automatically hide all events with their start date before today and the negative number will exclude that Event Category ID from your list. That way you also do not need to change “active” to “expired” manually. 🙂

    Hope it helps. 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Exclude Specific Event Category from Blog Feed’ is closed to new replies.