• Hello,
    I put a function inside function.php:

    if ( is_page('1237') ) {
    function exclude_category( $wp_query ) {
        // Add the category to an array of excluded categories. In this case, though,
        // it's really just one.
        $excluded = array( '-18' );
        // Note that this is a cleaner way to write: $wp_query->set('category__not_in', $excluded);
        set_query_var( 'category__not_in', $excluded );
    }
    add_action( 'pre_get_posts', 'exclude_category' );
    }

    the function works without the if statement, while with the if the target page continues to show the category 18.

    The page 1237 loads the blog template.

    how can I modify the if statment to activate the function only on that page?

The topic ‘exclude category from certain page’ is closed to new replies.