Support

Account

Home Forums Add-ons Repeater Field Order CPT Archive by nested Date Field within a Repeater

Helping

Order CPT Archive by nested Date Field within a Repeater

  • I have Custom Post Type (CPT) of Event, which has a Repeater Field named dates, with a Date Field sub_field named date. I am looking to order the Archive results for Events by the most upcoming date in the Repeater field.

    Currently I have the following.

    
    $date = date('Ymd');
    
    $args['suppress_filters'] = false;
    $args['meta_query'] = array(
      array(
        'key' => 'dates_$_date',
        'compare' => '>=',
        'value' => $date,
        'type' => 'DATE',
      )
    );
    
    $args['meta_key'] = 'dates_$_date';
    $args['order'] = 'ASC';
    $args['orderby'] = 'meta_value';

    The meta_query seems to be working because all past dates are being filtered, but the order functionality isn’t working as I’d hoped.

    Is this the right way to approach this issue? Any issues standing out?

    Thanks!

  • This cannot be done. In order to order by a field the values must all have the same meta key and this is not the case with repeater sub fields.

    See this

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.