• 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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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.

    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.

    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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exlcude Events from Blog page’ is closed to new replies.