Support » Fixing WordPress » excluding and including categories

  • Resolved nyx1961

    (@nyx1961)


    Please note that the site isn’t live as the person I’m helping with it doesn’t want it live until it’s finished. :\

    I need to build a site with two separate blog pages. I don’t want to use a subdomain because I need both blogs on the same installation / database.

    Blog 1 includes all but one post category. Blog 2 includes only the single post category that is excluded from Blog 1.

    I’ve added ‘category_name’ => ‘blog2’, to query_posts array Blog 2’s template to get only one category showing on Blog 2’s blog page.

    I cannot figure out how to exclude only that single Blog 2 category from Blog 1. I don’t want the category excluded from the entire site but I don’t want it showing up on Blog 1’s blog page or in any other context to Blog 1.

    The Ultimate Category Excluder plugin doesn’t work in this situation as it excludes the single category from all archives, for example. I’ve tried adding the following code to my functions.php but that hid the category from the entire site, not just the from Blog 1.

    function exclude_category( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
    $query->set( ‘cat’, ‘-158’ );
    }
    }
    add_action( ‘pre_get_posts’, ‘exclude_category’ );

    I’m an average WordPress user and I can usually figure these things out on my own with this forum and/or Google but this has me baffled. I would greatly appreciate any help.

    • This topic was modified 1 year, 5 months ago by nyx1961.
    • This topic was modified 1 year, 5 months ago by nyx1961.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Perhaps it would help if you stop thinking of it as if there were two sites when there is only one. Instead of using a category to distinguish the special posts, you could use a custom post type for them, or even a custom taxonomy. This gives you something extra to set them apart, they will not be mixed, and have different URLs to show them with.

    In ‘the loop’ you can exclude a category by using (‘cat=-catID’) where catID is the numeric category ID (notice the minus).

    This link explains it well https://css-tricks.com/snippets/wordpress/remove-specific-categories-from-the-loop/

    Thank you both so much for getting back to me. 🙂

    JNashHawkins, thank you for the link. I added ‘cat=-158’ to the Blog 1 loop but it didn’t work. Thank you for trying. 🙂

    Joy, I didn’t explain myself very well. I apologize. I’m not thinking of them as two separate sites but rather two separate blog sections on one site which has a home page as well as several other pages. I will look into custom post types and taxonomies. Thank you! 🙂

    Joy, I just wanted to thank you again for your suggestion. It led me in absolutely right direction. I found the Custom Post Type UI plugin, with which I was able to do exactly what I wanted to do. 😀

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘excluding and including categories’ is closed to new replies.