How to restrict the search fields for a specific post type

Question

How can I restrict the search for a specific post type? I am using the following code in functions.php:

function searchfilter($query) { 
    if ( is_admin() || ! $query->is_main_query() ){return;}

    if( $query->is_main_query()  ) {
       $query->set( 'post_type', ['property']);
     }   
     return $query;
 }   
add_filter('pre_get_posts','searchfilter');
0
Michael 3 years 2019-12-04T04:02:11-05:00 0 Answers 85 views 0

Leave an answer

Browse
Browse