Query for posts that have certain value in a repeater field?

I have a custom post type that contains a repeater.

All I want to do is build my loop and select only the posts that have a certain value within any of their repeater rows.

If there was a post type for “states” and repeater for “cities”, I want to loop and select all states that have a city named “bigtown” or whatever. Seems pretty simple and basic to want to do a search like this.

I know I can do a meta query for a repeater meta-key, but the way ACF stores repeaters is using a combination key, so it might look like “states_0_cities” and “states_1_cities” and so forth. But how would I make my query loop without explicitly typing “0” or “1” since I don’t know how many rows it will have or which row might have bigtown? I need to search over all the rows.

I’ve been searching for hours and it seems like I’m the only person on the internet who ever wanted to find posts where a repeater row has some value. I feel like I missed a simple thing!

How do I do that in Bricks query loop?

I’m not sure what the solution is, but this sounds like something that requires custom code in the query loop “query editor”.

If the repeater data was stored in a single meta row string (like “city 1, city 2, city 3”), you could use the LIKE comparison operator to find if a value exists in the repeater. But not if the values are stored in separate rows.

That wouldn’t work in the query editor. There is just no way to loop through and search agains the dynamic keys in the DB.

Probably a pure PHP solution could work, but I think the query would be a little intense and cause a slowdown.

It seems to me, the repeater field is not designed to be searched, it’s designed to hold some data we can loop over when showing the post it belongs to, but not to query against.