Hey there,
I'm developing a storage room booking website for my client with Carbon Fields 2.2. Unfortunately,
deleting an entry from the complex field with about 100 entries is very slow and causing some unwanted error messages/logs.
I expect to delete an entry fast from the complex fields with about 100 entries.
It takes about 10 seconds to delete an entry from the complex fields. Some browsers log this slow behavior in the console and my client told me about an error window saying "Script failure" in IE.
<?php
namespace Selfstorage1230\Admin\Meta_Box;
use Carbon_Fields\Container\Container;
use Carbon_Fields\Field;
use Selfstorage1230\Helper\Room_Helper;
if (!defined('ABSPATH')) {
exit('Not allowed to access pages directly.');
}
/**
* @since 1.0
*/
class Storage_Room_Meta_Box
{
/**
* @action carbon_fields_register_fields
* @since 1.0
*/
public function render(): void
{
$container = Container::make('post_meta', 'prefix_storage_room', __('Storage Rooms', 'storage'))
->where('post_type', '=', 'prefix_storage_room')
;
$this->add_rooms_for_xyz_street($container);
}
/**
* @since 1.0
* @param Container $container
*/
protected function add_rooms_for_xyz_street(Container $container): void
{
/** @var Field\Complex_Field $complex_field */
$complex_field = Field::make('complex', 'prefix_rooms', __('Rooms', 'storage'))
->set_layout('tabbed-vertical')
->set_duplicate_groups_allowed(false)
->set_classes('prefix-carbon-fields-rooms')
->setup_labels([
'singular_name' => __('Room', 'storage'),
'plural_name' => __('Rooms', 'storage'),
])
;
$rooms = Room_Helper::get_rooms_for_xyz_street();
foreach($rooms as $number => $room) {
$label = sprintf(__('Room %s', 'storage'), $number);
$name = sprintf('room_%s', $number);
$complex_field->add_fields($name, $label, [
Field::make('hidden', 'number', __('Number', 'storage'))
->set_value($number)
,
Field::make('text', 'area', __('Area', 'storage'))
->set_width(50)
->set_required(true)
->set_help_text(__('The available area in m².', 'storage'))
,
Field::make('text', 'moving_boxes', __('Moving boxes', 'storage'))
->set_width(50)
->set_required(true)
->set_help_text(__('The number of moving boxes.', 'storage'))
,
Field::make('text', 'rent', __('Weekly rent', 'storage'))
->set_width(50)
->set_required(true)
->set_help_text(__('The weekly rent in €.', 'storage'))
,
Field::make('text', 'deposit', __('Deposit', 'storage'))
->set_width(50)
->set_required(true)
->set_help_text(__('The deposit in €.', 'storage'))
,
Field::make('text', 'height', __('Height', 'storage'))
->set_required(true)
->set_help_text(__('The height in m.', 'storage'))
,
Field::make('textarea', 'description', __('Description', 'storage'))
->set_help_text(__('A meaningful description.', 'storage'))
,
]);
}
$container->add_fields([$complex_field]);
}
}
I have installed Carbon Fields 2.1 before and switched to Carbon Fields 2.2 for testing. This problem occurs in both versions. Additionally, the language of the screenshots is German ;)


Hi @AlexBa ,
When does the issue occur? On deleting the entry from complex or when you save the post after that?
Hey @deqngeorgiev,
The issued is occurring on deleting an entry from the complex field. Sry for the late reply :)
Can you test your complex field on a clean WordPress installation with some of the default themes and without any other plugins? I've tested your code with more than 100 entries and deleting an entry doesn't take so much time.
You could also record a performance profile with the devtools and have a look at that, it might help to know which functions are taking so long.
Remember that the data in complex fields is not saved in a custom sql table, it is been saved in many custom fields and then processed by PHP to an array.
To avoid these kind of performance issues you should separate the rooms to post type "room" and each room should be a post.
The fact that its "possible" to save 100 rooms in a complex field, doesn't mean it is the efficient way to do it :)
Most helpful comment
Remember that the data in complex fields is not saved in a custom sql table, it is been saved in many custom fields and then processed by PHP to an array.
To avoid these kind of performance issues you should separate the rooms to post type "room" and each room should be a post.
The fact that its "possible" to save 100 rooms in a complex field, doesn't mean it is the efficient way to do it :)