same behaviour on my script with an ACF array and the missing possibility to address a specific row. I can only address “count=1” for the first row but I have some Arrays with three rows and “count=2” or “count=3” etc. doesn’t work.
@besim could you clarify what you mean by this? I’m not sure what you mean when you refer to “rows” or what exactly an “ACF array” is. I assume you mean that you have an ACF repeater field and you’re able to limit your loop to one item in the repeater field using count but you’re not able to limit your loop to two or three items. Is that right?
@avanti Query parameters are loop-type-specific, so I’m not sure that query parameters from the post loop type like exclude are even supposed to work on an ACF relationship loop type (or a repeater loop type for that matter). I think the idea here is that an ACF relationship field is simply a list of posts, it’s not a query, which means you can’t filter it because it’s simply looping through the posts you’ve defined in the relationship field. Same idea with the repeater field, L&L isn’t querying data, it’s just looping through the information in your field. It is possible to sorta “convert” an ACF relationship loop into a post loop, at which point it actually is querying your posts and you’ll be able to use all the query parameters from the post loop type.
That being said, I’m not sure if the specific exclude parameter would work because then you’d effectively be saying “loop through these specific posts, but also don’t loop through this same post I’ve already told you to loop through” which doesn’t work logically. Might still work though so it’s worth a try. Failing that, maybe you could achieve that with something like this:
Maybe there’s a better way to work with the Format tag so you’d have to tinker around with that, but I think you get the idea. I’m not sure this is a bug so much as a logical limitation that’s not fully explained in the documentation. I imagine you could approach this the same way with a repeater field, it would just depend how your repeater is set up and what fields you’ve defined inside it.
In any case, we definitely need to improve the ACF page of the docs to clarify this.
Thank you for the explanations and examples, i understand an ACF loop is different from a standard WP Posts query.
But they both loop through Posts, so i guess there should be a way to filter the ACF loop so the current Post is not returned in the loop (that’s my goal).
I’ll check your Posts loop suggestion.
If not as a loop parameter, maybe at most simple by setting a conditional in the loop that would check the Post ID and exclude the current Post where the ACF Relationship is used on.
Very sorry all, i realize i confused ACF Repeater and ACF Relationship.
So, i posted in an unrelated topic… my apologies for the trouble.
And my initial code is wrong as well, i should have written:
<Loop acf_relationship=relationship_name exclude="123">
<Field title /> // Post with ID 123 is not supposed to be returned
</Loop>
Just FYI, this is what i wanted to do, excluding the current Post from an ACF Relationship loop (not an ACF Repeater loop), and it works using a conditional like that:
<Set name=current_post><Field id /></Set>
<ul>
<Loop acf_relationship="relationship_name">
<If field="id" is_not value="{Get current_post}">
<li><Field title /></li>
</If>
</Loop>
</ul>
I am reviving an old thread here but I also needed a reliable way to target a repeater row.
@benjamin your recommended logic worked. The only downside is that if the repeater rows are reordered, it will change what is presented on the frontend.
I found a blog with a simple way to add a unique ID field to ACF with a little PHP. Working great so far.