WordPress.org

Ready to get started?Download WordPress

Forums

How to exclude categories from the archives list? (2 posts)

  1. Who_Dat
    Member
    Posted 2 years ago #

    I have several categories of posts that don't belong in the blog...they're used for other purposes. I've excluded those categories from the blog posts, but they still show up in the archives...or rather, they still create a listing in the archives list.

    I've tried this in the functions file...

    function exclude_category($query) {
    if ( $query->is_archive ) {
    $query->set('cat', '-3 -4 -5');
    }
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');

    ...but it doesn't work. Now, the months of the excluded posts continue to show up in the list, but clicking them takes you to a 404 page. How do I exclude them entirely?

  2. vtxyzzy
    Member
    Posted 2 years ago #

    Should your category ids be comma-separated?

    $query->set('cat', '-3,-4,-5');

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.