ACF Relationship Loop orderby/sort using event date field

Hi @danaskallman, I initially thought this thread might be related to some bug with sort_field but I was taking another look at this “bug” report the other day and I noticed something I hadn’t before: the query parameters you’re using to filter your loop here are query parameters from the post loop, but those same query parameters aren’t officially supported on an ACF relationship loop. I think that might be your issue here. Maybe in a previous version of the plugin, the ACF relationship loop supported filtering using query parameters from the post loop, but this doesn’t seem to have ever been documented and may not actually have been intended anyway.

If you want to safely use the query parameters from the post loop on the posts listed in your ACF relationship field, you might want to “convert” your ACF relationship field into a post loop which I assume should allow you to use all those query parameters from the post loop. You can let me know if this works for you. The way I’d do this would be to feed your ACF relationship field to the id parameter of a post loop (or in your case, an event CPT post loop) like this:

<Loop type="event" id="{Field related_events}" sort_field="_eventorganiser_schedule_start_start" sort_type="date" sort_date_format="d-m-Y" sort_order="desc">
  <li><a href="{Field url}"><Field title /></a> - <Date format="l, F j, Y"><Field _eventorganiser_schedule_start_start /></Date> at <Date format="g:i a"><Field _eventorganiser_schedule_start_start /></Date></li>

Does that work for you?

1 Like