acf/save_post
function generate_unique_field_name($field_name, $field_group_key) {
global $wpdb;
$escaped_field_name = $wpdb->esc_like($field_name) . '%';
$existing_field_names = $wpdb->get_col(
$wpdb->prepare(
"SELECT DISTINCT meta_key FROM $wpdb->postmeta WHERE meta_key LIKE %s AND post_id IN (
SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'field_group_key' AND meta_value = %s
)",
$escaped_field_name,
$field_group_key
)
);
$i = 1;
$new_field_name = $field_name;
while (in_array($new_field_name, $existing_field_names)) {
$new_field_name = $field_name . '_' . $i;
$i++;
}
return $new_field_name;
}
function update_field_names($post_id) {
// Получаем данные о группе полей, связанной с постом
$field_groups = acf_get_field_groups(array(
'post_id' => $post_id,
));
if (empty($field_groups)) {
return;
}
foreach ($field_groups as $field_group) {
$fields = acf_get_fields($field_group);
foreach ($fields as $field) {
if ($field['key']) {
$field_name = $field['name'];
$field_key = $field['key'];
// Генерируем уникальное имя поля
$new_field_name = generate_unique_field_name($field_name, $field_group['key']);
// Обновляем имя поля
update_field('field_'. $field_key, 'field_' . $new_field_name);
}
}
}
}
add_action('acf/save_post', 'update_field_names', 20);
<script src="<?php echo get_template_directory_uri(); ?>/папка/скрипт.js"></script>
loop: true
поставил loopFill: true,