• Resolved thisisedie

    (@thisisedie)


    Hiya WordPressers.

    I need a little help. I have a fiction section on my website. I have it set up so I can write a fiction post and choose say “short stories” as the category and it will automatically be posted under short stories on the fiction page. That’s why I’m using posts instead of pages. With me so far? Ok… I want the fiction stuff to be completely separate from regular blog posts so I use this in my functions.php:

    add_filter('pre_get_posts', 'exclude_category');
    function exclude_category($query) {
    if ( $query->is_home || $query->is_archive || $query->is_search || $query->is_feed) {
    $query->set('cat', '-9');
    }
    return $query;
    }

    to eliminate those posts from everything except the fiction page. The trouble with this is that the is_archive part stops me from being able to sort posts by category in admin. My question is — is there a way around this? I’ve tried everything I can think of.

    Thanks for your time 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • Don’t run the function in the admin section.

    add_filter('pre_get_posts', 'exclude_category');
    function exclude_category($query) {
    if (is_admin()) return $query;
    if ( $query->is_home || $query->is_archive || $query->is_search || $query->is_feed) {
    $query->set('cat', '-9');
    }
    return $query;
    }

    Wouldn’t it be easier to create a category template for your special category and just eliminate that category from all other pages?

    Thread Starter thisisedie

    (@thisisedie)

    Thank you so much, that worked perfectly.

    Well if I understand what you mean with the category template it wouldn’t be easier. The fiction section isn’t a category page. Its a page in which I’ve set up multiple loops to pull up the titles of the pieces in several categories. I have them all in one main “fiction” category but they’re also in separate categories like short stories, bits & pieces, etc. And I want all the fiction excluded from everything.

    Thanks again 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Holy Messed Up Admin Filtering Batman!’ is closed to new replies.