How to exclude a post from my home page main query?
-
Hello everyone. I am looking for some help excluding a post from my home page main query.
I am using this code:add_action( 'pre_get_posts', 'add_my_post_types_to_query' ); function add_my_post_types_to_query( $query ) { if ( is_home() && $query->is_main_query() ) $query->set( 'post_type', array( 'post', 'custom' ) ); return $query; }
taken from WordPress Codex to display my custom post type on home page together with my regular posts. It is working perfectly and I don’t want to change anything. But let’s say I have a custom post type post with id=5 for example and I would like to exclude it from the above query. How to achieve that? Any help appreciated.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to exclude a post from my home page main query?’ is closed to new replies.