Hi, how can I sort rows of an ACF repeater based on a subfield value ?
This expression doesn’t work for now :
<Loop acf_repeater=field_name orderby_field=subfield order=desc>
<Field subfield />
</Loop>
Thank you !
Hi, how can I sort rows of an ACF repeater based on a subfield value ?
This expression doesn’t work for now :
<Loop acf_repeater=field_name orderby_field=subfield order=desc>
<Field subfield />
</Loop>
Thank you !
Hi Guillaume,
I haven’t tested it, but I think it could work using sort_field
, documented here.
<Loop acf_repeater=field_name sort_field=subfield sort_order=desc>
If the field value is a number, you can try adding sort_type=number
.
The difference between sort_field
and orderby_field
is that the latter is converted to a direct database query, which is limited to raw field values - which means most ACF field types are not supported, other than plain text values. In contrast, sort_field
will sort the loop items after the database query, using the same function as the Field
tag, which should work with ACF repeater field’s subfields.
Yes, it works. Thanks !
Hi Eliot,
I have tried this :
<Loop acf_repeater="wk_timeline_feed" sort_field="post_datetime" sort_type="date" sort_date_format="d/m/Y H:i" sort_order="desc">
<Field post_datetime />
<Field post_content />
</Loop>
But the rows in the repeater aren’t sorted by desc date. Do you know if there is any limitation on this use case ?
Best