Kriuchko
1/8/2019 - 2:58 PM

Search by post type search only post type

Wordpress search specific post type

add_filter( 'pre_get_posts', 'tgm_io_cpt_search' );
function tgm_io_cpt_search( $query ) {
    if ( $query->is_search and $_GET['search'] == 'publications' ) {
		$query->set( 'post_type', array( 'publications' ) );
    }

    return $query;
}