# Real estate website with Kirby

**URL:** <https://forum.getkirby.com/t/real-estate-website-with-kirby/1402>\
**Category:** Questions\
**Tags:** v2\
**Created:** [June 20, 2015, 10:44am UTC](https://forum.getkirby.com/t/real-estate-website-with-kirby/1402 "2015-06-20T10:44:28Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![SQBiz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sqbiz/32/5014_2.png) [@SQBiz](https://forum.getkirby.com/u/SQBiz)\
**Post date:** [June 22, 2015, 7:45pm UTC](https://forum.getkirby.com/t/real-estate-website-with-kirby/1402/9 "2015-06-22T19:45:27Z")

</div>

There’s a lot you can do using Kirby’s built-in `filter()` and `filterBy()` methods. I’m building a site right now that is a repository of a bunch of books, and browsing will be primarily through searches:

[![](https://dzwonsemrish7.cloudfront.net/items/0z0L1Y0H0V413J0i1t1E/Image%202015-06-22%20at%2012.34.45%20PM.png) ](https://dzwonsemrish7.cloudfront.net/items/0z0L1Y0H0V413J0i1t1E/Image%202015-06-22%20at%2012.34.45%20PM.png)

Then there are two ways I handle search queries - if a book contains a certain attribute (if it’s included in the Modern Library, for instance), and then, a basic filter. This allows for a lot of compound filtering.

The request is sent as a JSON object, via ajax, to a search script. This may be much more than what you’re looking for, but, I thought I’d post this here for anyone else to use / reference / critique:

```auto
<?php
define('DS', DIRECTORY_SEPARATOR);
require($_SERVER["DOCUMENT_ROOT"] . DS . 'kirby' . DS . 'bootstrap.php');
$kirby = kirby();
$site = $kirby->site();

$params = $_POST;

$books = $site->pages()->find('writers')->children()->visible()->children();

function contains($str, array $arr) {
  foreach($arr as $a) {
    if (stripos($str,$a) !== false || $a = "none" && strlen($str) == 0) return true;
  }
  return false;
}

foreach ($params as $param => $param_array) {
  switch($param) {
    case "regions":
      $books = $books->filter(function($book) use ($param_array) {
        if (contains((string)$book->region(), $param_array)) {
          return $book;
        }
      });
      break;
    case "languages":
      $books = $books->filter(function($book) use ($param_array) {
        if (contains((string)$book->language(), $param_array)) {
          return $book;
        }
      });
      break;
    case "collections":
      $books = $books->filter(function($book) use ($param_array) {        
        if (contains((string)$book->collections(), $param_array)) {
          return $book;
        }
      });
      break;
    case "filter":
      foreach($param_array as $filter => $filter_value) {
        switch ($filter) {
          case "min_pages":
            $books = $books->filterBy('page_count', '>', $filter_value);
            break;
          case "max_pages":
            $books = $books->filterBy('page_count', '<', $filter_value);
            break;  
          case "min_decade":
            $books = $books->filterBy('year_published', '>=', $filter_value);
            break;
          case "max_decade":
            $max = ($filter_value == 'max') ? 200000 : $filter_value;
            $books = $books->filterBy('year_published', '<=', $max);
            break;
        }
      }
      break;
  }
}

```

---

_[View the full topic](https://forum.getkirby.com/t/real-estate-website-with-kirby/1402)._
