Exclude post type from main page

I found a way to exclude specific category from main page, but I don’t know what should I change in order to exclude specific project type from home. I want to move projects categorized as ‘2018’ there to some kind of archive (ex. to …/project-type/2018/), to make them available for users, but not necessarily directly from the home page.
Could you please help me? The code that I have found to exclude post categories is attached below.

    function exclude_category( $query ) {
      if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'cat', '-1' );
    add_action( 'pre_get_posts', 'exclude_category' );


Hello Szymon,

Create a new 2018 category and choose parent relationship.


So new category 2018 link will be yoursite.com/project-type/2018/

Doesn’t it work for you?


Hi Kharis, thank you for your reply.

Actually the part you mentioned I’d already done, the issue is that I don’t want projects categorized as 2018 to be visible in the homepage as well. I want to start whole history in 2019 on my page from scratch, but with an opportunity to look back to the posts posted last year. Sure - that kind of archive as you wrote (…/project-type/2018) sounds fine to me, but still I want those projects out of my homepage.

Have you got any ideas about this?