Viewing 10 replies - 16 through 25 (of 25 total)
  • Thread Starter Isolacious

    (@isolacious)

    I’m using it for just one category, but I don’t see why it wouldn’t work for many. Just separate the category numbers by a space.

    lestermc

    (@lestermc)

    i try it for like 7 categories and doesn’t work but ??

    Thread Starter Isolacious

    (@isolacious)

    Unless you’re using the latest version of WordPress try putting a – before the category number

    greenflag

    (@greenflag)

    Yes i found the same thing – it only works with 1 category.

    Thread Starter Isolacious

    (@isolacious)

    So I guess you’re using an older version of WordPress?, I’m currently using 3.1 and I don’t need the -.

    greenflag

    (@greenflag)

    i’m using 3.1. the way of doing it mentioned in 1st post here allowed for multiple cat exclusion like this:

    -1 -2 -3 -4 etc

    the way otto suggests seems to work for only for 1 category – meaning:

    1 2 3 4 wont work

    lestermc

    (@lestermc)

    Yeah it only works for one category

    lestermc

    (@lestermc)

    This plugin is working!!! click here

    mmorpglife

    (@mmorpglife)

    If you want to fix it for multiple categories on your own without using a plugin you can change your exclude function to something like this:

    function exclude_category($query) {
    $exclude_categories=array(‘-1′,’-2′,’-3′,’-4′);
    if ( $query->is_home ) {
    $query->set(‘category__not_in’, $exclude_categories);
    }
    return $query;
    }
    add_filter(‘pre_get_posts’, ‘exclude_category’);

    NOTE: use your own category number in the $exclude_categories array.
    NOTE 2: I’ve noticed that using positive numbers for categories works just as well.

    BRILLIANT FIX

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

    Thanks @otto! I wasted about 3 hours trying things this morning before it occurred to me this might be a 3.1 bug… and your function totally fixed my problem in 5 seconds.

    have made a note, too, @mmorpglife of your multi-category fix.

    thankful there are people like you who can think in code, cuz i surely cannot. ??

Viewing 10 replies - 16 through 25 (of 25 total)
  • The topic ‘exclude_category Doesn't work with WordPress 3.1’ is closed to new replies.