Inspiry Menu Created with Sketch.
RELATED TO: Real Homes Theme

Refining search results could be very important for some of our clients. So, in this article, you will understand and learn how can you refine search results according to your requirements.

How to refine search results based on the property status:

You can refine the search results by using the following code in your theme’s functions.php file.


function inspiry_filter_search_results($search_args) {
  $status_to_exclude = array('for-sale');
  if( isset( $search_args[ 'tax_query' ] ) ) :
    $search_args[ 'tax_query' ] = array_merge($search_args[ 'tax_query' ], array(
    array(
      'taxonomy' => 'property-status',
      'field' => 'slug',
      'terms' => $status_to_exclude,
      'operator' => 'NOT IN'
    )
    ));
  else :
    $search_args[ 'tax_query' ] = array(
    array(
      'taxonomy' => 'property-status',
      'field' => 'slug',
      'terms' => $status_to_exclude,
      'operator' => 'NOT IN'
    )
    );
  endif;
  return $search_args;
}
add_filter('real_homes_search_parameters','inspiry_filter_search_results');

You just have to change the value of the variable called $status_to_exclude¬†and put the slug of the property status you want to exclude from search results. For example, in the above code, we are refining our search results to not display the properties with the status “For Rent“.

One more important thing to note is the correct slug. You can get the property status slugs by editing the Property Status as shown in the screenshot.

In the case of multiple statuses to be excluded you can put them by adding a comma to separate them. Please check the following code:

$status_to_exclude = array('for-sale', 'for-rent', 'sold', 'available-to-visit');

In the code above we are excluding the properties based on 4 different property statuses.