Support

Account

Home Forums General Issues Storing repeater values as one single array in the database Reply To: Storing repeater values as one single array in the database

  • I could always generate the array after save and then delete the repeater, but it seems a bit messy :

    add_action('save_post', 'save_repeater_as_array');
    function save_repeater_as_array($post_id) {
    	$repeater = get_field('my_repeater', $post_id);
    	$json = json_encode($repeater);
    	update_field('json',$json,$post_id);
    	
    	if (!empty($repeater)) {
    		while (delete_row('my_repeater', 1, $post_id));
    	}
    }

    Also, I’ll have to rebuild the repeater on page load with JS, but that’s okay I don’t mind putting in the work.