Acf_date and loop count

Hey Paul, good thinking, you’re on the right track and I think the only reason your last approach doesn’t work may be because of a bug.

The reason that the first approach doesn’t work is that your loop is getting three items before the If tag runs. So it gets whatever the first three posts are that match your query, and then the If tag filters it to only show results that also match your logic. So if a post matches the query parameters but not the logic, it’ll get counted toward the count=3 but then won’t be displayed because it doesn’t fit the logic in the If statement. That’s why you need to put the logic/filter/query parameters inside your loop tag so that it knows how to filter the results of the query while the query itself is happening. You can check out the filtering the loop section of the docs for a bit more info on how to think about that.

Regarding your issue with nothing showing up, I just tested the template you shared and I was able to confirm that it doesn’t seem to be working with custom_date_field_value=current which is what’s written in the docs. I did some digging and found this post from Eliot and it inspired me to try with custom_date_field_value="{Date format=Ymd}" which seems to work correctly. In that post, Eliot mentions using custom_date_field_value=today and interestingly enough, that seems to work correctly as well. So I wonder if there was some update where current was replaced with today. I imagine in an ideal world, both would work since current is pretty commonly used elsewhere in L&L.

I hope this discovery gets your template working correctly and I’ll report this so that this query parameter is made to work with current again in a future update.

1 Like