Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
To show a custom post type in WordPress’s front-end search, make sure its registration does not exclude it, then add its post type key to the main search query with pre_get_posts. Include the other types you want to keep searchable—such as posts and pages—in the same array.
1. Check the post type’s search setting
Find the arguments passed to register_post_type() for your custom type and check exclude_from_search. WordPress defines true as excluding that type from front-end search and false as allowing it. If the argument is omitted, its default is the opposite of the public setting; a public post type therefore defaults to not being excluded. See the WordPress register_post_type() reference.
The type’s registered key—not its display name—is what you will use in the query. For example, if the key is event, use event in the post_type array below.
Recommended Free Tools
2. Add the type to the front-end main search query
Use the pre_get_posts action to set the post types for the main search query. Add this to a site-specific plugin or your theme’s functions.php, changing event to your registered key and adjusting the array to match the content your search should return:
#1 Best Overall
function mysite_include_event_search( $query ) {
if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
$query->set( 'post_type', array( 'post', 'page', 'event' ) );
}
}
add_action( 'pre_get_posts', 'mysite_include_event_search' );
The array contains post, page, and event so those types can appear together. If you set post_type to only the custom type, ordinary posts and pages will no longer be included by this customization.
pre_get_posts runs after query variables are created and before WordPress executes the query. The callback receives the query being changed, so use its is_main_query() and is_search() methods to target the front-end main search request. The ! is_admin() condition keeps this front-end adjustment from changing admin queries. See the WordPress pre_get_posts reference, which cautions that global conditional functions may test a different query object.
Rank #2
3. Choose the right place for the code
If a plugin registers the custom post type, prefer its supported settings or filters over registering the same type a second time. The Plugin Handbook notes that registering a custom post type does not add it to the main query automatically and points to pre_get_posts for query changes. It also recommends placing post type functionality in a plugin so the type remains available when the theme changes. See Working with Custom Post Types.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesIf you are building a separate query rather than changing the site’s main front-end search, set the appropriate arguments on a WP_Query instance instead. WordPress recommends pre_get_posts for modifying the main query, and WP_Query or get_posts() for general post queries; see the WordPress query_posts() reference.
Quick Recap
Best Value
Rank #4
Rank #3
4. Troubleshoot missing results
- Check the key: Confirm the exact registered post type key and use that value in
post_type. - Check registration: Verify that
exclude_from_searchis not set totrue, and review whether the type is publicly queryable. - Check which query is changing: Confirm the callback runs on the front-end main search request, not just on an archive or a secondary query.
- Check the array: Include every content type that should remain searchable alongside the custom type.
- Check other code: Search plugins, theme code, or other filters may also change search arguments; review them if expected entries still do not appear.
- Check content visibility: Confirm the entries have a status and visibility suitable for public search. The WordPress references above do not determine the cause of a particular site’s missing results.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

