Question regarding Askbug search box
Hello Jayanta,
I think all you need is this:
/** * Add all CPT to search query. */ function anspress_add_cpts_to_search( $query ) { // Check if search page. if( is_search() ) { // Get post types. $post_types = get_post_types( [ 'public' => true, 'exclude_from_search' => false ], 'objects' ); $searchable_cpt = array(); // Add available post types. if( $post_types ) { foreach( $post_types as $type) { $searchable_cpt[] = $type->name; } } $query->set( 'post_type', $searchable_cpt ); } return $query; } add_action( 'pre_get_posts', 'anspress_add_cpts_to_search' );
Note: this hook includes all CPT in search query. If you want only specific CPT then replace
get_post_types
with array of CPT.
Rahul Aryan commented on answer
Rahul Aryan commented
There are already lots of plugin for that purpose. Try searching for “WordPress search suggestion plugin”.
Well, got that. Thank you so much. But what about a quora type live searchbox?