WordPress   

Include Custom Posts in Search in WordPress

function custom_search( $query ) {
   if ( is_search() && $query->is_main_query() && $query->get( 's' ) ){
        $query->set( 'post_type', array(
            'post', 
            'books',
        ) );
    }
}
add_filter( 'pre_get_posts', 'custom_search' );
Need Professional Support for Your Website Problems?

Whether you're facing website issues or struggling with code implementation, our team is here to assist. Hire us to get your website back on track.

Hire Us