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
- Combining queries with different arguments per post type
- Custom Post Type and Taxonomy URL rewrite
- register_post_type & ‘register_meta_box_cb’ argument
- 404 on child page when parent page slug is identical to custom post type
- How to replicate some of Drupal Views functionality in WordPress?
- Archive page with multiple taxonomies rewrite
- Date archives for custom post type
- WP Rest API Querying Custom Posts by ACF fields
- display multiple term post from taxonomy in a single page
- Allow Author role to publish one post type and not another
- custom taxonomy – Template not working
- How to show post title outside of loop? [closed]
- Query current and future events, ordered by begin date
- adding .current* tags to custom post types and taxonomies
- How to get custom post type menu_name?
- List Posts of a Custom Post Types Ordered by Terms of a Custom Taxonomy?
- Removing Duplicate Custom Taxonomy Terms from within a Dropdown Select?
- Saving repeated option values in a custom query
- Remove custom post type slug not working for child pages
- I am facing problem in my archive page , it is partially working
- Rewrite rules for custom post type slug
- Check if admin is editing page or custom post type
- Make slug as ID Number for custom post types
- Admin notice not displaying
- Custom Image Thumbnails of Different Sizes
- wp_set_object_terms() not adding new term to custom post and custom taxonomy
- Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far
- Prevent stripping MathML tags on post save
- How to set order for a custom post type
- Display users uploaded files as posts
- Custom admin post.php page
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- Use Custom Post Type archive page for the taxonomies term archive page
- Is it possible to have dedicated page for parent/child taxonomy?
- Nested Custom Post Type or Custom Post Type Parents?
- How to use TinyMCE Editor for one of my custom post meta field?
- Custom post type permalink returns 404
- filter search custom field query
- Using wp_query to modify the loop in index.php for a CPT
- Different slug taxonomy for two different CPT
- Getting WordPress Flexslider Item Number
- Why does my taxonomy have a category style div id?
- Postname on unique permalink structure appends “-2” for a custom post type. How can I get this to stop happening?
- Undefined $post in wp_query
- fetch custom post by meta key if key value is does not know
- Get image from external URL
- Issue with Custom Post Types and Single
- How do I edit the WordPress post.php file?
- Posts are not rendering perfectly [closed]
- Echo custom post meta from options array
- Filtering the_content, but still need to display the unfiltered content inside filter
- Value of post meta dropdown is not showing in WordPress
- Looping through custom taxonomy and display custom post types (Custom Post Type UI)
- Function to add custom HTML into head in custom post-type list page
- Invalid file type when using wp_upload_bits to upload PDF to a custom post type
- What is the parameter : ‘Customs-fields’
- set post_type based on custom taxonomy permalink
- Get previous and next custom post by custom field
- Order posts by taxonomy terms
- Creating post template for a Custom Post Type
- WP Admin Dropdown List Filter for custom (ACF) field on custom post type(s)
- Why are custom taxonomies only appearing on the edit page of one of these types, but not the other?
- Add Custom Field in Product in WP Admin and send to Order Webhook
- How to associate custom taxonomy terms with custom post type?
- Is it possible to create 2 unique titles for an Events custom post type: Upcoming Events and Past Events?
- get_the_terms child terms for current post/custom post only
- Custom Post Type Query by user id
- Display title of custom post type dynamically
- select custom post type on regular post
- woocommerce post_type conflict with existing post type
- Work and Display a Custom Post Type as a normal Post
- Get month and day from a Date Picker custom field
- Is it possible to add and display custom post types to an array?
- How to change post status link order(priority) on cpt listing page
- How to loop custom post type posts by author?
- Timetable of Custom Meta Data using Custom Post Type and Custom Taxonomy
- Change the contents of a dropdown through the admin panel?
- Linking from a list of custom post type items to a single – get_post_permalink not working correctly
- After wp_insert_post() custom post type does not show in the admin
- Custom post type is_singular condtional not working when managing sidebar display
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?