How to Include Pages in WordPress Search

WordPress search can include pages already. If yours shows only posts, first check the search form, theme and plugins for a setting that narrows the results.
In WordPress core, a search without an explicit post type uses any, which includes searchable post types. A standard page is not excluded simply because it is a page.
Check the restriction before adding code
Search for a distinctive phrase from a published page while signed out. Then check whether your search form submits a post_type=post parameter or a search plugin limits its results to posts.
Change an existing search setting where possible. Adding another filter without understanding the first one makes the result harder to maintain.
Limit the main search to posts and pages
If your intention is specifically to search posts and pages, the example below sets those two types. It excludes other custom post types, so do not use it unchanged if products or another content type should appear.
The guards follow WordPress’s pre_get_posts guidance: change the main front-end search query, leaving admin screens and secondary loops alone. The example also skips AJAX and REST requests; a custom search endpoint needs its own review.
function digitalboom_search_posts_and_pages( $query ) {
if ( is_admin() || wp_doing_ajax()
|| ( defined( 'REST_REQUEST' ) && REST_REQUEST )
|| ! $query->is_main_query() || ! $query->is_search() ) {
return;
}
$query->set( 'post_type', array( 'post', 'page' ) );
}
add_action( 'pre_get_posts', 'digitalboom_search_posts_and_pages' );
Add it where updates will preserve it
Use a small site-specific plugin or an existing child theme’s functions.php. WordPress documents why parent-theme edits can disappear during updates. Keep a backup and try the change on a staging copy before applying it to a live site.
Do not add a second opening PHP tag inside an existing PHP block. Give the function a unique name if the site already defines it.
Verify the actual result
Repeat the same signed-out search and check that a matching published post and page appear. Check a second results page as well. If results still differ, inspect the search plugin and template rather than adding more untested filters.
This example changes the query types; it does not change relevance ranking or make private content public. For more practical publishing work, see the Digital Tools guides.



