how can i restrict the saerch fields only for specific post type

Question

I used this code on 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 1 year 0 Answers 83 views 0

Leave an answer