I guess you mean overriding the post type of the main search query on the front-end. You could try:
add_action( 'pre_get_posts', function ( WP_Query $q )
{
if (
! is_admin()
&& $q->is_main_query()
&& $q->is_search()
)
$q->set( 'post_type', 'film' );
} );
This way you don’t need a secondary search query or mess directly with the globals.
Related Posts:
- How to create a custom search for custom post type?
- Extending the search context in the admin list post screen
- Include custom taxonomy term in search
- Creating a search form for custom fields
- Searching multiple custom post types and pages
- AJAX search on post pages by custom post type
- How can I change the admin search posts fields?
- group search results by post type?
- Development of a WordPress Search Plugin – Best Practices
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- Simple way to search custom-post types only
- Pushing a custom post type to the top of the search results
- Custom post type admin search
- Using standard search function with custom post type
- Search everything (posts, pages, tags, cpt, meta)
- Search Custom Post Type with all meta attached?
- WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?
- filter search result with custom post type meta key
- Custom search for custom post type, custom meta and search fields
- Search Post Title Only [duplicate]
- Customize Search to only search current custom post type
- How to search from specific post type with tags?
- custom search result page
- How to search CPT’s by meta query from the admin dashboard?
- Customize Search Results for Custom Post Type
- multiple search forms and search results
- Custom Fields vs Separate Table
- How to create an advanced filter search?
- How to search map address in custom post type?
- Custom Search for Drafts in Custom Post Type
- Multiple meta_values in the pre_get_posts filter?
- How to order separated Custom Post Search results
- Custom post type search using $_SESSION and pre_get_posts
- How to stick custom post at the top in search results
- Can I search only some of the fields of a custom post type?
- Make parts of your wordpress website completely built with data from external APIs?
- Custom post type not showing in search result
- What to and how to proceed with CPT to make DB small and efficient?
- Auto Complete Search
- Remotely search WordPress sites using xml-rpc
- BBPress Search results in WordPress search
- Limit Search to Post Type With Apostrophe return search not found
- Search filter triggered & sort by custom post type
- Set Custom Post Type in Widget Settings for use in Widget
- Displaying and searching Custom Posts
- Searching Custom Fields
- dropdowboxes with pre-selected custom fields optios that filters the results according seach needs
- How to let users choose where to search for posts?
- Can NOT search my custom post type?
- Custom post_type search pages
- Pagination Error : Duplicate argument being outputted
- Custom Empty Results page for my Custom Post Type
- Select2 AJAX and WP Query Returns ALL and does not filter
- search custom post type by custom fields on front end
- Category Search / Custom Post Type search on my website. Custom Post Types that are “page-like”?
- Filtering custom posts by custom fields (ACF) [closed]
- Searching post types
- Blank search results on custom search
- Search CPT Title AND Meta
- Building a Data Intensive Website with WordPress
- Display future posts in search
- Modifying search results based on post_type
- WordPress CPT Taxonomy Dashboard Search – How to include taxonomy in search?
- Is it possible to get the specific content on the search page?
- Search for custom field input of a custom post type in ajax live search
- In the php, how can I have a category of a custom post type display?
- Search Function not searching correct custom_post_type even though post_type is defined in search args
- Search only one custom post type
- Query first and last name from custom post type
- Custom search for a custom post type in WordPress
- Advanced search form with multiple custom fields
- Search in multiple specific post types
- I can not display search template created from a post type custom
- Creating a search results page from a custom post type in a plugin?
- Search custom post type result in same template page
- Include images from pages in wp search.php results in default wp search
- Search facility with directories
- Create Second Search Page Only for Custom Post Type
- custom search form for custom post
- Custom post url in search.php isn’t the correct rewrited url
- custom search results – order results differently by post type
- Conditional posts in WP_query for search
- Post search not looking at post title since 4.4.2 upgrade
- Manually build WP_Query
- Trying to modify custom search function in plugin to search postmeta table for keyword as well as posts table
- pre_get_posts not firing at all
- Custom Search not working
- Custom post type blog pagination conflict
- Is it good practice to search for custom posts based on custom field values?
- Diffrent search templates for different post types
- Cannot get query var ‘post_type’ to work
- Problem with custom post type search
- admin search of pages returns custom post types
- Why does ‘exclude_from_search’ exclude a custom post type from WP_Query?
- Custom Field Search
- Custom post archive with search, is_search() is false?
- Group search results by post type, but having a unique heading for each section?
- Fix Custom Post Type not appearing in search results?
- Search and filter terms of a custom post type only and display results
- How can I retain get_post_type() in between consecutive searches after a search returns no results?