To show a custom post type in your site’s front-end search results, make sure its registration does not exclude it from search, then add its registered type key to the front-end main search query. WordPress’s pre_get_posts hook is the documented way to adjust that query before it runs.
1. Check that the post type is eligible for search
Find the post type’s register_post_type() arguments and inspect exclude_from_search. WordPress defines true as excluding the type from front-end search and false as allowing it. If the argument is omitted, its default is the opposite of the value of public. See the register_post_type() reference.
Eligibility and query composition are separate concerns: a type that is not excluded can still be absent if the search query does not request it. If a plugin registers the type, use that plugin’s supported setting or filter where possible rather than registering the same type a second time. WordPress recommends placing custom post type functionality in a plugin so it can remain available when the theme changes; see Working with Custom Post Types.
2. Add the type to the front-end main search query
Add this code to the plugin or theme functionality that manages your site’s search. Replace event with the exact registered post type key, and adjust the array to include the content types you want search to return.
Free tools Windows power users keep installed
One-click scans. No signup required.
#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 pre_get_posts action fires after query variables are created and before WordPress runs the query. Using the passed $query object’s is_main_query() and is_search() methods, with an admin check, confines the change to the intended front-end search request. WordPress cautions that global conditional functions may test the global query rather than the query instance being modified; see the hook reference.
Include every type that should remain in the results. For example, an array containing only 'event' narrows the search to that custom type; it will no longer request ordinary posts or pages. The example preserves both by specifying 'post', 'page', and 'event'.
Rank #2
3. Confirm the change and troubleshoot missing results
- Check the type key. Use the registered post type key—not its display name—in the
post_typearray. - Check registration settings. Confirm
exclude_from_searchis nottrue, and review whether the type is publicly queryable. - Check where the callback applies. Confirm the code runs on the front-end main search query, not only on an archive or secondary query.
- Check the full array. Make sure it contains all the existing content types you intend to keep searchable.
- Check other query modifications. If results are still missing, review theme code and plugins that also alter search arguments.
- Check entry visibility. Confirm the custom entries have a status and visibility appropriate for public search. The registration and query settings alone do not establish whether an individual entry should be publicly visible.
When the results come from a custom query
The code above targets the main search request. If a search interface runs its own query, set the appropriate WP_Query arguments for that query instead of changing the front-end main query. WordPress’s query_posts() reference recommends pre_get_posts for modifying the main query and WP_Query or get_posts() for general post queries.
Quick Recap
Best Value
Rank #4
Rank #3
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.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problems

