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 !