Pagination, filtering, date field query

I see, that does narrow down the cause of the issue. Yes, it’s exactly how you said in the last sentence.

Pagination happens when the loop is created at the start. And any filtering done inside the content, using If tag, will be applied after the items are paginated already, inside of each item as they’re being looped.

What’s happening in the second code snippet is that items which don’t match the condition just have empty content - but they still exist as items within a page.


For pagination to work, the filter (using If tag) needs to be converted into a query (for the Loop tag).

Fortunately the condition is a date field query, which is supported by the Post loop type. In the linked documentation page, the following query parameters are relevant:

  • custom_date_field
  • custom_date_field_compare
  • custom_date_field_format
  • custom_date_field_type
  • custom_date_field_value

The last parameter is a question. In the docs, I see it supports the value current, but not today. (I believe the reason is that today is a duration, not a specific point in time.) The expected date format is Ymd, so we can create it with the Date tag.

Something like this could work:

<Loop type=post category=presseartikel paged=10
  custom_date_field=ankundigung_zum
  custom_date_field_compare=before
  custom_date_field_value="{Date format=Ymd}"
>
2 Likes