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:
- Mixing custom post type and taxonomy rewrite structures?
- How to rewrite URI of custom post type?
- Custom rewrite rules for archive page and single post
- WordPress Rewrite Rules for Custom Post Type and Taxonomy
- Custom post types – Use post_id in permalink structure
- Custom Post Type and Taxonomy URL rewrite
- Custom post type permalink: only use %post_id% and remove %postname%
- Rewrite custom post type rss feed links
- Add category to custom post URL
- Creating a custom public user page
- Archive page with multiple taxonomies rewrite
- rewrite get parameter with custom post type
- How to filter custom post type archive by meta value
- Taxonomy archives based on Custom Post Type
- Multiple custom post types using the same taxonomy = URL frustrations
- Taxonomy page returns 404 page not found
- Child pages on hierarchical Custom Post Types 404s
- Remove unwanted part of permalink custom structure from CPT url?
- How to have a custom URL structure for a custom post type?
- Permalinks for CPT breaks permalinks to pages
- WordPress custom post type url change
- Changing a custom post type “has_archive” after registered
- Possible to change the slug of default post type?
- Custom Post Type rewrite redirects to homepage
- Custom Post Type slug same as page name causing a conflict
- Adding paged query to custom URL rewrite
- Custom Post Type rewrite rules not working, how to alter the rewrite order?
- Rewrite Custom Post Type URL slug
- Customising rewrite rules for CPT single post URL to work as paged URL
- Remove custom post type slug not working for child pages
- Custom WP TItle from custom template with dynamic URL structure
- Rewrite rules for custom post type slug
- Change URL of posts and also Custom Post Type
- Custom Post Type rewrite
- How to have custom post type /example/ and then posts /example/posts.html
- Remove url rewrites for registered taxonomies
- 404 Issue w/ Custom Post Type – using Meta for Permalink rewrite
- Get Taxonomy Term Title by it’s URL
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- Using taxonomy term in CPT permalink – Pages 404’s
- How to add rewrite rule to custom post type with parent in url with cpt ui?
- Programmatically rewriting slug through functions.php but returns 404
- How do I change the custom taxonomy slug to be the same as the custom post type slug?
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Rewrite custom post type url – Multiple post types
- Why isn’t my custom post type archive URL translating?
- Rewrites/query for multiple hierarchical custom post types
- Post Type rewrite rule to point to custom Page/template
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- Specific routing for CPT
- Lost of query parameter when using permalink
- Custom permalink with child taxonomy terms
- Custom post type archive with page as parent url
- 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
- Custom Post Type rewrite url to /category/pagetitle [duplicate]
- Paging not working for hierarchical custom post type
- redirect old post type url to new structure url
- Custom Post Type URL Rewriting
- Archive page for a custom post type using WPML
- 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
- How to rewrite custom slugs that follow my rules
- Custom post type with custom taxonomies structure url not working archive of CPT
- What is the best way to relate different custom post types?
- Allow child pages with the same base as the CPT slug
- How to work with URLs where sometimes a post or a subcategory is in the same part of the URL structure
- How to make 2 (or more) custom post type post pages sit under the same slug?
- Display content based on multiple URL parameters—pretty URL or query string