I am guessing that you are searching for post and if post not found then you want to display page.
If you are using WordPress default search then you can try this code
function my_cptui_add_post_type_to_search( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
if ( $query->is_search() ) {
$query->set(
'post_type',
array( 'post', 'page' )
);
}
}
add_filter( 'pre_get_posts', 'my_cptui_add_post_type_to_search' );
Related Posts:
- How to remove slug from hierarchical custom types in 3.5.2
- Custom post type yearly/ monthly archive permalinks
- Meta_Query as a way how to setup CPT permalinks – is it a good thing?
- How can I rewrite URLs to pass taxonomy and post type values to the query?
- Is it possible to change the URL of custom post types to hide the post type slug?
- Removing base slug from hierarchical custom post type
- Rewriting ‘rewrite’ slug for custom post type used by plugin
- Adding meta values to permalink
- WordPress custom taxonomy URL rewrite on spelling errors
- How can i avoid the permalink start with ‘blog’ while using the custom post type?
- Custom Posttype Inheritance (and url structure)
- Adding %author% in custom post type URL structure?
- Defining a default page for custom post type
- Pass parameter to custom post type single while keeping clean url
- Display CPT taxonomies as an archive page
- Including two taxonomies in a permalink structure
- WP Rewrite Rules – Custom post type & taxonomy
- Removing CPT slug from URL results in 404 error for archive page
- URL Design for Sub-Posts?
- Many to Many Taxonomies or rewrite rules?
- Remove base slug in CPT & CT, use CT in permalink
- remove post-name from title in custom post type
- Getting Post ID from slug during init
- Rewrite custom post & taxonomy to share same URL path
- How do I list terms of a custom taxonomy at i.e. domain.com/brands/
- Permalink Structure problem with cpt and custom taxonomy
- how to use two permalinks for one custom post type
- Adding a date archive to Custom Post Type
- Custom Taxonomy 404
- Bulk 301 redirect for custom post type
- single-{post_type}.php is not loaded despite flushing rules
- Custom Permalink Tag breaks Pagination
- Custom Permalink for Taxonimie and Custom Post Type
- Rewrite numeric ID parameter for hierarchical custom post type
- Custom Post Type and Custom Taxonomy Permalinks
- Pagination problem
- Custom Post Type Post have a Child `Page` Post Type Post
- In WordPress how do you create a custom post type with the author’s name in the slug?
- How can I display an archive of only one category of my custom post type?
- remove permalink “front part” for custom post type
- Permalink Structure CPT With Custom Taxonomy Fails
- Conditionally custom post type url rewrite
- Query var removed after rewrite
- Change Permalink Structure for Tag.php template
- Making a custom help center page
- Add archive slug to default post post type
- Custom Post type and permalink settings
- Rewrite post type slug only for child theme
- Can’t get custom rewrite tag, query var, permastruct (permalink structure), and rewrite rule to work properly together
- How can I make the slug of the taxonomy also the slug of the custom post
- WordPress custom post type permalink rewrite shows page not found
- Customize Custom Post Type URL
- Custom Post Type and Category Base Rewrite Issue
- Versioned Custom Post Type (Not the same as revisions)
- Rewrite URL of Custom Post Type for Jobs
- Custom post Type, child of a Page?
- Hide or disallow default custom post type url?
- Custom taxonomy returns 404
- Pretty URLs and custom post types
- Specific routing for CPT
- Lost of query parameter when using permalink
- Pagination custom post type not working with rewrite slug
- Custom Rewrite Rule for Custom Post Type with URL Param
- WordPress custom slug rewrite
- WordPress Custom Post Type – Rewrite Query
- After creating Custom post type by user delete old one
- Set parent for custom post type archive rewrite url
- Dynamic CPT permalink structure based on ACF field value
- URL Rewrite – Page Archive
- Urls in Custom Post Type work for Terms but not for its Taxonomies
- custom post archive URL is wrong
- Rewrite rules for custom post type
- Custom taxonomy and post type rewrite rules
- Custom Post Type and Taxonomy Rewrite Error
- custom posts permalinks url rewriting
- WordPress is ignoring my post rewrite rule
- Url Rewriting a dynamic wordpress page with parameters
- Custom Permalink For Custom Post Type – Working Fine But Broken For Pagination
- I want to rewrite the URL of a specific post with a specific custom field to easily analyze in Google Analytics
- Duplicate content problems after adding an archive page to the article’s post type
- Display CPT taxonomies as an archive page
- How to fix 404 on post after prepending Custom Post Type url with Custom Taxonomy Term slug
- Redirect Custom Post Type from Child Taxonomies
- Custom post type structure + permalink structure
- Rewrite URL of Specific Post of Custom Type
- Using get_post_type with a custom URL format?
- Custom post type rewrite and wp_pagenavi interfering with each other
- Show index and not the archive for “Dog Custom Post” with default slug
- Paging not working for hierarchical custom post type
- redirect old post type url to new structure url
- Custom Post Type URL Rewriting
- Why is a custom post type’s URL “/?cposts=name-of-the-post” but default post’s URL is “/?p=ID”?
- Customize category URL
- Custom Post Type Rewrite Rule
- rewrite rules add a folder in the path
- How can you preserve URLs when moving posts to a custom post type?
- Custom Post Type Base URL
- Custom Taxonomy in Permalink from post type
- Custom Post Type and single-posttype template
- Menu Structure and URL structure, with Pages and Post-Type-Posts