WordPress.org

Forums

Allow only one category for blog page (4 posts)

  1. hrrubin
    Member
    Posted 1 year ago #

    I have three categories:

    rr (private)
    grafisk design (published)
    blogpost (published)

    The category 'rr' is on the frontpage and 'grafisk design' is on another page. But I only want 'blogpost' to be part of the blogpage.

    How can I do this?

  2. esmi
    Forum Moderator
    Posted 1 year ago #

  3. hrrubin
    Member
    Posted 1 year ago #

    So I take this and place in function.php?

    function exclude_category( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'cat', '-rr,-grafisk-design' );
        }
    }
    add_action( 'pre_get_posts', 'exclude_category' );
  4. esmi
    Forum Moderator
    Posted 1 year ago #

    You might want to change the category names to ids. I can't recall whether names will work or not.

Topic Closed

This topic has been closed to new replies.

About this Topic