WordPress.org

Ready to get started?Download WordPress

Forums

Help with Category Exclusion (2 posts)

  1. Tranny
    Member
    Posted 3 years ago #

    I used this code in the functions.php file for exclusion of categories:

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

    but after upgrade to v3.1 it results in fatal error. Could someone help me with how to do it in 3.1?

  2. vtxyzzy
    Member
    Posted 3 years ago #

    It did not give me a fatal error, but I had to change it to this before it worked:

    function exclude_category($query) {
    if ( $query->is_home() ) {
       $query->set('category__not_in', array('91'));
    }
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');

    Note the parens after is_home.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.