Jump to content

Search filter help


Recommended Posts


I'm quite new to processwire but I already fall in love with it. But now I'm struggeling with a problem for more than a week, since I'm not very good at PHP programing, but am willing to learn.

I want to make a real estate page and I want to focus on the search capabilities of processwire.

I made a structure

Real estates (template=realestates)

 - Country 1 (template=country)

    - Region 1 (template=region)

        - Product 1 (template=realestate-input)

    - Region 2

        - Product 2         

 - Country 2

    - Region 3

        - Product 3

 - Country 3

Hidden Options 

 - Rooms ( to use as page field in template=realestate-input)

   - 1 room

   - 1,5 room

   - ...

 - Type ( to use as page field in template=realestate-input)

   - Appartement

   - House

   - Holiday house

I've looked at skyscrapper search examples but I can't crack it to fit in my case.

I've made a form which generates Country's and Region's:

<form id='skyscraper_search' method='get' action='<?php echo $config->urls->root?>iskanje/'>

	<h3>Real estates</h3>

	<label for='search_keywords'>Keywords</label>
	<input type='text' name='keywords' id='search_keywords' value='<?php 
		if($input->whitelist->keywords) echo $sanitizer->entities($input->whitelist->keywords); ?>' />

	<label for='search_Location'>Location</label>
	<select id='search_Location' name='location'>
		<option value=''>Vse</option><?php 
		// generate the location options, checking the whitelist to see if any are already selected
		foreach ($pages->get("/nepremicnine/")->children() as $country) {
			$selected = $country->name == $input->whitelist->location ? " selected='selected' " : '';
			echo "<option$selected value='{$country->name}'>{$country->title}</option>"; 
			foreach ($country->children() as $Location) {
			$selected = $Location->name == $input->whitelist->location ? " selected='selected' " : '';
			echo "<option$selected value='{$country->name}/{$Location->name}'> - {$Location->title}</option>";


	<p><input type='submit' id='search_submit' name='submit' value='Search' /></p>


On click I want to make selector look for template=realestates-input on selected parent of upper form.

The following code works for regions, becouse their childrens are "realestate-inputs", but if I select country I want to display all realestates in every region.

// most of the code in this template file is here to build this selector string 
// it will contain the search query that gets sent to $skyscraperList 

$selector1 = ''; 

// we use this to store the info that generates the summary of what was searched for
// the summary will appear above the search results
$summary = array(
	"location" => "", 
$location = $input->get->location;
echo "<br>" . $location . "<br><br>";

// if a location is specified, then we limit the results to having that location as their parent
if($input->get->location) {
	//$location = $pages->get("/realestates/" . $sanitizer->pageName($input->get->location));
	$location = $pages->get("/realestates/{$input->get->location}");	
	if($location->id) {
		$selector1 = "parent=$location, ";
		$summary["location"] = $location->title;
		$input->whitelist('location', $location->name); 

//$selector1 .= "template=realestates-input, ";
$matches = $pages->find("$selector1,");
echo "<br>Found: " . count($matches) . " match<br>";

echo $selector1;

foreach ($matches as $match) {
	echo "<br>" . $match->title;

When I'll crack this one I will only need to filter the search results based on selected options on realestates-input template. But also don't know how to make a selector for that.

I would really appriciate any guidance to complete my task.

Thank you

Link to comment
Share on other sites

Than you for guidance.

I've decided to let go the options to search by other countries for now, but I have found a way, how to.

I made countries and regions as $page field select and then put selector "country=england" or "region=westminster" ...

I just felt it more natural to catogarize them by pages for editing purposes.

Now I have every relaestate-input in realestate category.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...