Home › Forums › Backend Issues (wp-admin) › Saving a post causes few sub-rows form the end under repeater field to be delete
Hi,
Something very weird.
I made some custom functionality to make it happens the way I need, I’ll write here all the flow:
– I have created a new custom post type called event
. I also created a custom taxonomy under event
called event_type
.
– I created from GUI a field-group with tabs and in every tabs there are custom fields.
– In one of the tabs(last of them) there is a repeater and a sub-repeater.
– Inside this sub-repeater there is a group, and under this group(let’s call it specific-event
), I have SELECT field which I populate all terms from the custom taxonomy event_type
.
– I want that in the SELECT under the specific-event
, when the user picks a term, it will show custom group under specific-event
with custom fields.
So what I did:
I have created programmatically each group and set the parent
attribute to be specific-event
field key.
Each group automatically gets ‘hidden’ class.
In the JS API, I have created some logics, to detect any term select and make the correct group(I have created programmatically) to be visible.
– So far all good, the custom functionality seems to be working,
Everytime I change the term in the select under specific-event
it shows me the correct sub-group under specific-event
.
BUT, when I add lets say 7 parent rows in the parent repeater, and inside I add more 3-4 sub-rows each,
It doesnt save all… after saving I gets only 4 parent rows, and not 7. Something very very wierd.
This is the code for the custom groups:
add_action('init', function() {
if (function_exists('acf_add_local_field_group')) {
acf_add_local_field(array(
'key' => 'field_event_event',
'label' => 'נקודת עניין',
'name' => 'event__event',
'aria-label' => '',
'type' => 'select',
'choices' => array(),
'return_format' => 'array',
'ui' => 1,
'multiple' => 0,
'parent' => 'field_6441222b20c40'
));
acf_add_local_field(array(
'key' => 'field_event_time',
'label' => 'זמן',
'name' => 'event__time',
'aria-label' => '',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'taxonomy' => '',
'parent' => 'field_6441222b20c40'
));
$event_types = get_terms([
'taxonomy' => 'event_type',
'hide_empty' => false,
]);
foreach ($event_types as $event_type) {
$dynamic_fields = (!empty(TL_ACF::get_field('event-type__dynamic-fields', 'event_type_' . $event_type->term_id)) ? TL_ACF::get_field('event-type__dynamic-fields', 'event_type_' . $event_type->term_id) : array());
$field_group = array(
'key' => 'field_' . $event_type->term_id,
'label' => $event_type->name,
'name' => 'event__type-' . $event_type->term_id,
'type' => 'group',
'wrapper' => array(
'class' => 'hidden',
),
'parent' => 'field_6441222b20c40'
);
foreach ($dynamic_fields as $dynamic_field) {
$field_group['sub_fields'][] = array(
'key' => 'field_' . $dynamic_field['dynamic-fields__system-name'],
'label' => $dynamic_field['dynamic-fields__name'],
'name' => 'type-' . $event_type->term_id . '__' . $dynamic_field['dynamic-fields__system-name'],
'type' => $dynamic_field['dynamic-fields__type']['value'],
);
}
acf_add_local_field($field_group);
}
}
});
When fields disappear at the end of a repeater this is usually do to the PHP setting max_input_vars. This setting needs to be edited on your server/host. The default is 1000.
[Search Results]
After I posted this, I figured it out it’s related to the max_input_vars.
Thank you!
This specific back-end post saving, included lots of lots of vars… (fields inside groups inside repeater inside repeater). Any best practice for this?
Any way to optimize this max_input_vars? maybe I can make ACF splitting those post requests into several requests?
Thanks!
You can use pagination option for top level repeaters, it will not work for nested repeaters.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.