Forum

Thread tagged as: Question, Configuration

filter help please

Template snippet - users can choose to flag items as 'for sale' or 'syndicate shares available'

        <perch:if exists="sale_item">
                   <perch:content id="sale_item" type="select" label="Choose sale or syndication" options="For sale, Syndicate shares available" allowempty="true" />
          <perch:else />
        </perch:if>

Trying to filter to show items that are 'for sale' AND 'syndicate shares available' ... I currently only have one option, can I have more than one option in 'value' below??? Or have I formatted filter incorrectly?

'filter' => 'sale_item',
                'match' => 'eq',
                'value'=>'For sale',
Charlie Elsey

Charlie Elsey 0 points

  • 4 years ago

Hi

I think you only need to perform that test in the Perch template, full docs here)

Try this

<!--* THIS ADDS TWO CHECKBOXES *-->
<perch:if exists="sale_item OR syndicate">
<perch:content id="sale_item" type="checkbox" label="Sale item" value="sale_item" suppress="true" />
<perch:content id="syndicate" type="checkbox" label="Syndicate" value="syndicate" suppress="true" />
<!--* suppress="true" hides the output, but the ID can be used in your template *-->
</perch:if>
<!--* THIS USES THE VALUES TO SHOW A MESSAGE BASED ON WHAT CHECKBOXES HAVE BEEN CHECKED *-->
<perch:if exists="sale_item AND syndicate">
Item for sale and syndicate shares available
<perch:else />
<perch:if exists="sale_item">
Item for sale
</perch:if>
<perch:if exists="syndicate">
Syndicate shares available
</perch:if>
</perch:if>

You can also have multiple filters in an array, like this:

<?php
perch_content_custom('Something', array(
    'filter'=>array(
        array(
            'filter'=>'sale_item',
            'match'=>'eq',
            'value'=> 'Syndicate shares available'
        ),
        array(
            'filter'=>'sale_item',
            'match'=>'eq',
            'value'=> 'For sale'
        ),
    )
));
?>

See "Filtering by multiple fields" on this page: https://docs.grabaperch.com/functions/content/perch-content-custom/

Duncan Revell

Duncan Revell 78 points
Registered Developer

Not only, but also...

'filter' => 'sale_item', 
'match' => 'in', 
'value'=>'For sale,Syndicate shares available',

could work.

Ooooh yes good point Duncan - much more elegant

Thank you all so much for your help, sorry for delay in replying.