Forum
How to match more than one value when filtering
I have a testimonial area on most pages across a site. I've created a region on index.php using perch_content_create and then used perch_content_custom to filter and sort testimonials.
index.php page
<?php perch_content_create('Testimonials', array(
'template' => 'testimonial-section.html',
'multiple' => true,
));
?>
Within testimonial-section.html I've included a select field type so that I can display relevant testimonials on a page:
<perch:content id="testimonial_type" type="select" label="Type of testimonial" help="Select the category that most closely describes the type of testimonial" options="Healthcare, Charity, Voluntary, General" allowempty="false" required="true" suppress="true" />
Most of the time, I just want to filter by testimonial type and match one value. e.g.
<?php perch_content_custom('Testimonials', array(
'page' => '/index.php',
'template' => 'testimonial-section.html',
'filter' => 'testimonial_type',
'match' => 'eq',
'value' => 'Healthcare',
'sort' => 'testimonial_type',
'sort-order' => 'RAND',
'count' => '1',
)); ?>
In some circumstances I'd like to match by more than one value, for example, display a testimonial either from Charity or Voluntary testimonial type. How would I do this please?
Thanks
You can pass in a comma delimited string of values and use 'in' instead of 'eq'
https://docs.grabaperch.com/docs/content/perch-content-custom/
Brilliant, thanks Rachel – I'd tried using 'in' but with a space after the comma in the list. Working now!