Forum
Returning one repeater item with a checkbox in a multiple item region
I have a multiple item region, each with a repeater. I would like to use perch_content_custom to return one repeater item across the whole region at random, but only one that has a checkbox checked.
At the moment I am looping through the arrays that perch_content_custom is returning and matching against the checkbox field. Then using PHP rand to select one.
Is there a more efficient way to do this?
You should be able to filter the region on
repeater.field
having a checked value to only return items that include a repeater with a checked item.So that gives me items that have a repeater with at least one checkbox ticked?
Is there then a way to filter only the items within the repeaters that have a checkbox checked?
Right so I've managed to do that that last bit now too using another template, only now I need to select at random an item within the repeater.
I don't think we have anything to do that.
Okay thanks Drew. I've just done it using php for now suing the result from perch_content_custom. Just in case there's something to consider for a future update my use-case is:
Hello,
I just wanted to check if I've understood something in here correctly.
Using perch_content_custom() with a filter to match against a repeater will return all items in the repeater, not just the one that it matches? And other than looping through the array with PHP you cannot get just that one field?
I'm just checking as it's a problem I'm currently facing and am just writing a PHP loop to go through and only display what is needed, just want to make sure I am doing it right.
Thanks, Neil.
Hi Neil
You can return just one field using filter but I was trying to return only one field with a specific value.