• Resolved rs11

    (@rs11)


    Hi, I’m new to WordPress and have been trying very hard to make the exclude code below work. I’ve attempted many different variations.

    The goal is to allow two categories of posts to appear only on a home page of a WordPress website while a third category appears only on a separate draft page of the website. (And, later, a fourth category of posts will appear on a separate “page two” of the website). The home page was designed to be presented through an empty, linked “index.php” page. And the home page and the draft pages have their own linked templates (page-home.php and page-draft.php).

    What’s happening is that one command is overriding the other command and forces the one command to apply to both situations, no matter how I reword or re-order the command. It’s often the home page command that overrides the other, but sometimes it’s the other way around. (I’ve also tried labeling the page-home as home, index, etc.)

    If you have run across this problem before, I’d really appreciate your advice.

    function exclude_category($query) {
    if ( $query->is_page-draft.php) {
    $query->set(‘category__not_in’, array(1));

    }
    if ( $query->is_page-home.php) {
    $query->set(‘category__not_in’, array(2,3));

    }
    return $query;
    }
    add_filter(‘pre_get_posts’, ‘exclude_category’);

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘"Exclude Category" query isn't functioning’ is closed to new replies.