Home:ALL Converter>Wordpress Order Archive by ACF Repeater Field Date

Wordpress Order Archive by ACF Repeater Field Date

Ask Time:2022-05-24T01:08:37         Author:Terence Devine

Json Formatter

I have a WordPress site that has a custom post type of Event which includes an Advanced Custom Field (ACF) Repeater field with a date field included. I am looking to order the Event Post Type on the archive view by the earliest Date Field within the ACF Repeater.

I had tried using a nested meta_query by adding the key of dates_%_date but the returned Events don't seem to be in the proper order. The repeater field is named dates and the sub_field for it is named date.

Does the order of the repeater fields matter? IE: does it make a difference which entry in the repeater field has the date? I'm looking to compare ALL dates from the repeater field.

$args['meta_query'] = array(
  array(
    'key' => 'dates_%_date',
    'compare' => '>=',
    'value' => $today
   )
);

$args['meta_key'] = 'dates_%_date';
$args['order'] = 'ASC';
$args['orderby'] = 'meta_value';

Is there anything glaringly wrong in this query? Or another way to run this?

Author:Terence Devine,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/72352361/wordpress-order-archive-by-acf-repeater-field-date
yy