Hi, I’m trying to write a loop that filters a custom post type by a custom date field, and struggling to get it to work. The CPT represents running races and has a field (date and time of the race) and I want a list of upcoming races (i.e. next 5 after today). My CPT is setup using the “Toolset Types” plugin and printing the raw values it looks like a timestamp field.
I’ve tried this but it simply lists the earliest 5 events, not ones that are after today:
<Loop type=events custom_date_field=wpcf-start_date custom_date_field_format=timestamp custom_date_field_type=datetime custom_date_field_value=current custom_date_field_compare=after_inclusive order=asc orderby_field=wpcf-start_date count=5>
<a href="{Field url}"><Field title/></a> <Format date="Y-m-d H:i"><Field wpcf-start_date/></Format><br/>
</Loop>
(note that if I change custom_date_field_compare from after_inclusive
to after
it gives no results at all)
Another option I tried was to treat the field as a number and filter by timestamp value, but that doesn’t give any results at all (whether custom_field_type is timestamp or number):
<Loop type=events custom_field=wpcf-start_date custom_field_type=timestamp custom_field_compare=more_than custom_field_value="{Date format=timestamp}" order=asc orderby_field=wpcf-start_date count=5>
<a href="{Field url}"><Field title/></a> <Format date="Y-m-d H:i"><Field wpcf-start_date/></Format><br/>
</Loop>
Has anyone got any ideas what I am doing wrong please, and how to get L&L to work properly for this kind of thing?
Many thanks,
Chris