Home Forums Add-ons Repeater Field Order repeatable field by date in back-end


Order repeatable field by date in back-end

  • Hi there,

    first off, I’m not a very experienced PHP programmer and so far the support pages have been very helpful, thanks for that.

    secondly, here’s my problem:

    I have a repeatable field and one field in there is a date field. It’s basically a simple calendar: there’s a date field and a desciption field, and these are grouped in a repeatable field. My date field is called “datumprik” and the repeatable field that groups this and other fields is called “activiteiten” (pardon my Dutch!).

    What I want is that in the back-end the list is ordered by date when I save a post. The way it is now: all dates are show in the order I put them in, which is not desirable.

    I believe this guide contains the answer, but to be quite honest, I don’t know how to implement the code shown after “Advanced” correctly:

    In the example code I tried replacing the words “field_55121d86dd2f6” and “scores” one of these names. Nothing happens.

    Sorry for the n00by question, I hope a simple pointer will clear thing up. Thanks in advance.

    Lastly, there’s a couple of dead links on the support page mentioned (for instance click “acf/load_value”).

  • Thanks John, I will try this out today!

  • Tried all suggested solutions, nothing worked unfortunately.

    For instance, one of the examples, this is the code I use in my function.php:

    function my_acf_update_value( $value, $post_id, $field  ) {
    	$mc_sort_id_FIELD_KEY = 'field_59711bd65b276'; // Set this to the field key of your field called "mc_sort_id".
    	$order = [];
    	foreach ( $repeater as $i => $row ) {
    		$order[ $i ] = $row[ $mc_sort_id_FIELD_KEY ];
    	array_multisort( $order, SORT_ASC, $value );
    	return $value;
    add_filter( 'acf/update_value/name=datumprik', 'my_acf_update_value', 10, 3 );

    And this is where I got the values “field_59711bd65b276” and “datumprik”):


    So I want the backend to order ascending on the “datumprik” field. Am I missing something or is there something wrong?

  • Oh my… nobody here to help me out? Am I overlooking something? Any help would be greatly appreciated 🙂

  • OK, found out what went wrong. I hadn’t updated to PRO, so I could not get the field_XXXX etc from the field I wanted to sort on.

  • sorry for the late response. I personally have never had much luck with array multisort. For anyone else that has a similar problem I gave and example here using usort()

  • Also I would like to get a list of dates in the repeater field. I entered the code of the custom field given, I replaced the value of the repeater field, I’m using ACF PRO updated but it does not work. how did you do it? I would be very grateful if anyone can help me. Thank you!

  • Hi Federico!

    I was on a holiday so late reply here.

    Can you be more specific, do you have example code?

    Anyway, the code I used in my functions.php was:

     * Hooks the WP cpt_post_types filter 
     * @param array $post_types An array of post type names that the templates be used by
     * @return array The array of post type names that the templates be used by
    function my_cpt_post_types( $post_types ) {
        $post_types[] = 'beugel';
        $post_types[] = 'kingweg';
        $post_types[] = 'groep_8';
        return $post_types;
    add_filter( 'cpt_post_types', 'my_cpt_post_types' );
    function my_taxonomy_query( $args, $field, $post_id ) {
        // modify args
        $args['orderby'] = 'count';
        $args['order'] = 'ASC';
        // return
        return $args;
    add_filter('acf/fields/taxonomy/query', 'my_taxonomy_query', 10, 3);
Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.