Support

Account

Home Forums ACF PRO Unique, pre-populated repeater fields Reply To: Unique, pre-populated repeater fields

  • Alright, thanks for confirming this. I may get into some custom JavaScript at some point, but this particular field is mostly read-only, and for now can be set when saving the post.

    For future readers, I ended up making the field read-only when set to null, and then hooking into update_value to generate unique values there. I set the placeholder text to “Automatically generated on save”. Not the most elegant solution, but it works!

    function my_acf_generate_file_url($value, $post_id, $field) {
    
    	if ($value == NULL) {
            
            // generate GUID unique to each row of the repeater and it's value
    		$data = openssl_random_pseudo_bytes(16);
    		$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
    		$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
    		$value = vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
    	}
    
    	return $value;
    }
    add_filter('acf/update_value/key=field_xxxxxxxx', 'my_acf_generate_file_url', 10, 3);