Title: Search custom post types
Last modified: June 25, 2019

---

# Search custom post types

 *  Resolved [kptgreg](https://wordpress.org/support/users/kptgreg/)
 * (@kptgreg)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/search-custom-post-types-2/)
 * This does not seem to search custom post types, is there a way I can add that?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fsearch-custom-post-types-2%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  [Rafik](https://wordpress.org/support/users/rafikwp/)
 * (@rafikwp)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/search-custom-post-types-2/#post-11673411)
 * Hello,
 * This plugin also searches custom post type, but it will not search if the post
   type excluded from the search when post type registered.
 * You can use this code to get the result
    Please add below code in your active
   theme functions.php file
 *     ```
       function rc_add_cpts_to_search($query) {
   
       	// Check to verify it's search page
       	if( is_search() ) {
       		// Get post types
       		$post_types = get_post_types(array('public' => true, 'exclude_from_search' => false), 'objects');
       		$searchable_types = array();
       		// Add available post types
       		if( $post_types ) {
       			foreach( $post_types as $type) {
       				$searchable_types[] = $type->name;
       			}
       		}
       		$query->set( 'post_type', $searchable_types );
       	}
       	return $query;
       }
       add_action( 'pre_get_posts', 'rc_add_cpts_to_search' );
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Search custom post types’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/search-and-navigation-popup_ebf9fa.
   svg)
 * [Search and Navigation Popup](https://wordpress.org/plugins/search-and-navigation-popup/)
 * [Support Threads](https://wordpress.org/support/plugin/search-and-navigation-popup/)
 * [Active Topics](https://wordpress.org/support/plugin/search-and-navigation-popup/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/search-and-navigation-popup/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/search-and-navigation-popup/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Rafik](https://wordpress.org/support/users/rafikwp/)
 * Last activity: [6 years, 10 months ago](https://wordpress.org/support/topic/search-custom-post-types-2/#post-11673411)
 * Status: resolved