Forums

The Events Calendar
Exlcude Events from Blog page (5 posts)

  1. chris
    Member
    Posted 9 months ago #

    How would I go about writing a function for excluding the events that are listed as events, from showing on my blog page? I am assuming I can writie a simple function in my functions.php, but I don't know if you're using a custom post type or something else. Thanks.

  2. nhinshaw
    Member
    Posted 8 months ago #

    Chris,
    I add the following to my functions.php file:

    function exclude_category($query) {
    if ( $query->is_home || $query->is_blog ) {$query->set('cat', '-1');}
    return $query;}
    add_filter('pre_get_posts', 'exclude_category');

    Where '-1' is the category number assigned to your event posts.

  3. adamskalecki
    Member
    Posted 8 months ago #

    I added this in the functions.php file of my wordpress theme folder, replacing '-1' with 'Events' for the name of the category I am trying to exclude. It's not working. Maybe I can't replace the number with a category name? What am I doing wrong?

    Thanks.

  4. Roy
    Member
    Posted 8 months ago #

  5. adamskalecki
    Member
    Posted 8 months ago #

    That doesn't work either. I found that the category number assigned to the Events category was 6, so I tried this:

    function exclude_category($query) {
    if ( $query->is_home || $query->is_blog ) {$query->set('cat', '6');}
    return $query;}
    add_filter('pre_get_posts', 'exclude_category');

    ...but that didn't work either. Anybody else?

Reply

You must log in to post.

About this Plugin

About this Topic