Support

Account

Home Forums Add-ons Repeater Field Specify number of Repeater fields Reply To: Specify number of Repeater fields

  • For anyone else with this issue, I resolved it this way:
    I used the acf/load_value as outllined here: https://gist.github.com/theJasonJones/7061b8020e43a114756214e20c4d0ed9

    Fantastic Help!
    Instead of adding each item like they do int he tutorial, I had a global variable based on how many items I needed, then I looped through the “$value[] = array(…” creating as many repeater items as I need.
    Here’s my resultant code:

    // Sets the number of Repeater Confirm Ring Size items.
    add_filter('acf/load_value/key=field_5d366cc2c5656',  'afc_load_my_repeater_value', 10, 3);
    function afc_load_my_repeater_value($value, $post_id, $field) {
        global $ring_count;
        //Optional: Check for post_status otherwise published values will be changed.
        if ( get_post_status( $post_id ) === 'wc-processing' or get_post_status( $post_id ) === 'wc-pending') {
             //Optional: Check for post_type.
            if( get_post_type( $post_id ) == 'shop_order' ){
                if ($ring_count > 0){
                    $value	= array();
                    // Add field key for the field you would to put a default value (text field in this case)
                    for ($i = 0; $i < $ring_count; $i++) {
                        $value[] = array(
                            'field_5d366d10c5657' => '5'
                        );
                    }
                }
            }
        }
        return $value;
    }