you can try this one
function exclude_some_post_type($query) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_search || is_home() ) {
// in search page
$query->set( 'post_type', 'post' );
}
}
}
add_action( 'pre_get_posts', 'exclude_some_post_type' );
The function that applied to a pre_get_posts hook will set only default post type (post), and will ignore the other types in search or blog (home) page.
For further reading about pre_get_posts hook, please visit: https://developer.wordpress.org/reference/hooks/pre_get_posts/
Related Posts:
- Exclude post_type from admin comments_list
- Exclude Custom Post Type & Pages From Auto-Tag Function
- exclude custom post type by meta key in wp_query
- Exclude the parent custom post-type posts only
- Exclude specific taxonomy term when using wp_get_post_terms
- is there a way to retrieve posts that do not have a featured image assigned?
- How to create Blog Post Specific Widget
- ‘exclude’ argument is not working with get_posts for a custom post type
- Exclude custom taxonomy term posts from custom post loop
- link to a random custom post while excluding current post
- Exclude latest post from WP_Query taxonomy term loop
- Best way to change the blog page post type?
- Show only Current category and sub category of custom post wordpress
- Exclude a specific post in a Custom Post Type
- Skip latest 3 posts from loop
- How to display elements of different post types?
- Permalink for regular posts “/blog/”
- show 10 most recent custom post types excluding the one(s) from specific custom taxonomy
- Cannot exclude particular post from loop of custom post type
- How to get taxonomy category in permalink for each taxonomy OR How to give a parent page to a given taxonomy?
- Get the ID of the latest post
- Do_Shortcode not working for Embed
- How do you get the count of posts in an archive page?
- tag.php doesn’t work with tags on a custom post type post?
- Custom post type permalink: only use %post_id% and remove %postname%
- List most recent image uploads, but only for specific custom post type
- Fetching private posts or custom post types via WP-API with basic authentication
- Remove admin menu for custom taxonomy attached to custom post type
- How do I list custom taxonomy terms without the links?
- Page not found taxonomy custom post type
- how to filter by last name for custom post
- If featured image doesn’t exist, show post content
- Getting a div content of a post in wordpress?
- Order Posts by Taxonomy and Meta Value
- Custom comment status possible?
- Get categories for a specific post – Custom post type
- Rename a current used post type
- Include custom post types in categories widget
- Assign Page Template Within A Custom Post Type
- Group Custom post type in a page by its taxomony tag
- WPMU: Programmatically adding CPT posts to specific blog id
- add_meta_box: Datepicker like the one for postdate?
- Getting taxonomy terms used by custom post type
- Custom post types not imported properly
- query order by date on custom type: wrong order
- Custom field losing p tags on display
- How do I echo the post type?
- Error after deleting Custom Post Type with a function (no trash used)
- Using posts and postmeta table to store custom Address Book Plugin data
- Categories not working as expected with custom post type
- Custom Post Type rewrite rules not working, how to alter the rewrite order?
- error in Advanced Search Form for Custom Post Types in WordPress array_key_exists() expects parameter 2to be array, string given
- Rewrite Custom Post Type URL slug
- Posts navigation in custom post type single.php not working
- Calculating Bayesian average for custom post type
- How to customize admin posts based on the user who is logged in
- Custom post type – how can I make it a sub-url of another page?
- Merge multiple custom post types in a single archive template
- Problem adding column to WC Subscription [closed]
- Custom Post Type | Fatal Error on register_post_type()
- apply filters only to specific post listing without check the url parameters
- register_post_type exclude_from_search argument not working
- query posts and custom post type with meta key
- Custom Post Types for Support Ticket plugin?
- How to sort custom post type posts in default order by multiple fields?
- WordPress theme options vs custom post types
- if custom posts type exists and there are posts load script
- Custom Post-to-Post with multiple parents?
- Adding `supports` array to WordPress custom post type
- URI returns a post when it should return a 404
- Twenty Fifteen: Adjacent posts by menu_order [duplicate]
- Displaying a form for filtering in custom post type listing
- Query string parameters from custom fields, inconsistent results
- How to make custom post type feed title = taxonomies?
- Change meta box when the page’s template is changed
- Custom Post Type Loop throws 500 error when used in widget
- How can I update the permalink everywhere for a custom post type?
- create a template page for a post
- Adding Show Less/More link to Custom Post Meta
- custom admin screen or setting screen for a custom post type [duplicate]
- Get custom taxonomies from multiple posts
- Define new user capability for custom post types?
- Post image in WordPress not appearing on home page
- How to have the same url structure for both a CPT and a Taxonomy?
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- Featured image overlay when changing post status
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- Programmatically rewriting slug through functions.php but returns 404
- limit value taxonomy based on previous taxonomy value wordpress
- Problem: wp_query outputs all images on site
- pre_get_posts for custom page builder meta box
- Pre-styling post content to display in lightbox
- How to assign permissions for a CPT to a user
- Using POST method in meta box, no results
- Displaying Posts from Custom Post Types
- Custom Post Types strange pagination problem
- Custom fields disappearing when a custom post type is assigned
- displaying ACF Repeater Fields in Backend sorted by a subfield
- Display posts of only a certain category in WP Admin section?
- Search for portfolio tags & mixing portfoliotags and post tags