Loop showing posts 'after and including' an ACF datetime field

Hi,

I need to filter a loop by a ACF DateTime field and only show posts from today included and onwards.

I’ve tried a lot of combinations but haven’t nailed it yet, if anyone can spot what I am missing.
I’m still getting all posts (no filtering).

<Loop type=post_type_name custom_date_field=field_name custom_date_field_type=datetime  custom_date_field_compare=after_inclusive custom_date_field_value=current>

On a different note the Beaver template module is throwing errors and locking things up after an update to either L&L or BB (for me anyway). Insert by template shortcode still works great.

UPDATE: Managed to get this sorted with some help from @avanti

I’ll leave it here if anyone needs to filter CPT posts based on ACF datetime field and show future posts including today.

Useful for events, etc.

<Set yesterday>
  <Date format=timestamp>yesterday</Date>
</Set>
<Loop type=post_type_name sort_field=date_time>
 <If check="{Field acf_date_time=date_time format=timestamp}" more_than value="{Get yesterday}">

</If>
</Loop>
4 Likes

Regarding my post After 4.1.0 update template has no output about 4.0.2 / 4.1.0 update

This setup here is also broken in 4.1.0 but worked in 4.0.2 is there any change in syntax or is this also a sideeffect of the update?

I use it this way:

<Set yesterday>
  <Date format=timestamp>yesterday</Date>
</Set>

<If check="{Field acf_date_time=tmb_date_start format=timestamp}" more_than value="{Get yesterday}">

Here is a screen how it looks in LL 4.1.2

(all posts with Field acf_date_start has a date older than YESTERDAY are shown)

And here, how it should be, in LL 4.0.2

(all posts with Field acf_date_start has a date older than YESTERDAY are not shown)

The default format L&L uses when displaying ACF date/time/datetime fields has changed to respect the format set in the ACF settings, but that shouldn’t affect anything in your case because you’ve specified a format in your template (timestamp).

I’ve tested out a few things on the latest version of L&L with an ACF datetime field date_time_field set to right now and the logic still all works as expected.

<p><Date format=timestamp>yesterday</Date></p>

<p><Field acf_date_time=date_time_field format=timestamp /></p>

<p>
  <If check="{Field acf_date_time=date_time_field format=timestamp}" more_than value="{Get yesterday}">
    The date field is after yesterday!
    <Else />
    The date field is before yesterday.
  </If>
</p>

<p>
  <If check="1711097617" more_than value="1710979200">
    First number is bigger.
    <Else />
    Second number is bigger.
  </If>
</p>

Output:

1710979200

1711098516

The date field is after yesterday!

First number is bigger.

Is there any chance you’re using Beaver Themer to render this template? If so, that might be the issue and not any kind of template syntax. Seems like Eliot’s looking into that as we speak. If so, I might move this comment over to that thread to keep this issue consolidated.