Forum

Thread tagged as: Question, Discussion, Forum

Categories search cross

Hi, How can do a filter in "Categories" (e.g. quick search for real estate) for category1 (property type) + category 2 (location)+ category 3 (mode: to sale, to rent)?, i.e. that the user perform a search cross. Thanks

alex s

alex s 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not sure what you mean by 'cross' in this context, but see if this helps:

https://solutions.grabaperch.com/architecture/user-filtered-lists

alex s

alex s 0 points

Thanks Drew, it was exactly that, but it does not work properly. My idea is to open a results page as filter.php with this function as in example:

<?php
$filters = array();

if (perch_get('type')) {
    // if 'type' is on the URL, add a filter for bedrooms
    $filters[] = array(
        'filter' => 'type',
        'match'  => 'eq',
        'value'  => perch_get('type'),
    );
}

if (perch_get('beds')) {
    // if 'beds' is on the URL, add a filter for bedrooms
    $filters[] = array(
        'filter' => 'beds',
        'match'  => 'eq',
        'value'  => perch_get('beds'),
    );
}

if (perch_get('location')) {
    // if 'location' is on the URL, add a filter for the location
    $filters[] = array(
        'filter' => 'location',
        'match'  => 'eq',
        'value'  => perch_get('location'),
    );
}

// Unset the filters if none are used:
if (!count($filters)) $filters=false;

// Then get the list
perch_content_custom('Properties', array(
    'template'   => 'property_listing.html',
    'sort'       => 'price', 
    'sort-order' => 'DESC',
    'filter'     => $filters,
));
?> 
Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so what's not working?

alex s

alex s 0 points

If the form is the same page (filter.php) then the result should show it here, right? but shows nothing.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you posting the form to the new page?

alex s

alex s 0 points

No Drew

Drew McLellan

Drew McLellan 2638 points
Perch Support

That might be a good place to start.

alex s

alex s 0 points

Hi Drew, I've done everything like is in the tutorial: - a form: perch_form ('property_filter.html'); - the template of the form: property_filter.html - page filter.php with Filtering from the URL options

and is only sending the form in the dashboard Forms, what I need is that the user sees filter results. Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you included an app attribute on your form tag?

alex s

alex s 0 points

yes: <perch:form id="filter" method="get" app="perch_forms">

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so remove that.

alex s

alex s 0 points

done, but nothing happens.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What do you mean nothing happens? What do you see?

alex s

alex s 0 points

excuse me Drew if I am not very clear. What should happen is to show the search results.

Drew McLellan

Drew McLellan 2638 points
Perch Support

And what does happen? It's very hard to help if you can't tell us what's going wrong.

alex s

alex s 0 points

Hi Drew, I send you my page with the filter search https://www.sudamericapropiedades.cl/propiedades/filter.php Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

That looks like the form is working fine.

Where should the results be?

alex s

alex s 0 points

on the same page (or on another page, e.g. result.php, but I not know how to do) Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me the code you're using?

alex s

alex s 0 points

Ok. property_filter.html

<perch:form id="filter" method="get" >
    <div class="col-lg-12 col-md-12 col-sm-6">
        <div class="formBlock">
        <perch:label for="ciudad-o-localidad">Ciudad</perch:label>
        <perch:input type="select" id="ciudad-o-localidad" options=",Valdivia|valdivia,Puerto Montt|puerto montt,Osorno|osorno,La Unión|la union,Los Lagos|los lagos" class="formDropdown" />
    </div>
    </div>

     <div class="col-lg-12 col-md-12 col-sm-6">
        <div class="formBlock">
        <perch:label for="modalidad-u-operacion">Modalidad</perch:label>
        <perch:input type="select" id="modalidad-u-operacion" options=",Venta|venta, Arriendo|arriendo" class="formDropdown"/>
    </div>
    </div>

     <div class="col-lg-12 col-md-12 col-sm-6">
        <div class="formBlock">
        <perch:label for="tipo-de-propiedad">Tipo</perch:label>
        <perch:input type="select" id="tipo-de-propiedad" options=",Casa|casa, Departamento|departamento, Comercial|comercial, Oficina|oficina, Fundo|fundo, Parcela|parcela, Sitio|sitio, Terreno|terreno" class="formDropdown" />
    </div>
    </div>

    <div class="col-lg-12 col-md-12 col-sm-6">
        <div class="formBlock">
        <perch:label for="estado">Estado</perch:label>
        <perch:input type="select" id="estado" options=",Nuevo|nuevo,Usado|usado" class="formDropdown" />
    </div>
    </div>

   <div class="col-lg-12 col-md-12 col-sm-6">
    <div class="formBlock">
    <perch:input type="submit" value="Buscar" class="buttonColor"/>
    </div>
    </div>
</perch:form>

and filter.php

    <?php
$filters = array();

if (perch_get('ciudad-o-localidad')) {

    $filters[] = array(
        'filter' => 'ciudad-o-localidad',
        'match'  => 'eq',
        'value'  => perch_get('ciudad-o-localidad'),
    );
}

if (perch_get('estado')) {

    $filters[] = array(
        'filter' => 'estado',
        'match'  => 'eq',
        'value'  => perch_get('estado'),
    );
}

if (perch_get('modalidad-u-operacion')) {

    $filters[] = array(
        'filter' => 'modalidad-u-operacion',
        'match'  => 'eq',
        'value'  => perch_get('modalidad-u-operacion'),
    );
}

if (perch_get('tipo-de-propiedad')) {

    $filters[] = array(
        'filter' => 'tipo-de-propiedad',
        'match'  => 'eq',
        'value'  => perch_get('tipo-de-propiedad'),
    );
}

// Unset the filters if none are used:
if (!count($filters)) $filters=false;

// Then get the list
perch_content_custom('Propiedades', array(

    'template'   => 'lista.html', 

    'filter'     => $filters,
));
?> 

<?php
perch_form('property_filter.html'); 
?>