
SOLVED.
<?php
include 'wp-load.php';
print '<xmp>';
$post_type = 'MY_POST_TYPE';
$acf_field = 'ACF_FIELD_HAS_RELATIONSHIP';
$batch_size = 200;
set_time_limit(0);
$offset = 0;
$total = 0;
do {
$spots = get_posts([
'post_type' => $post_type,
'post_status' => 'any',
'posts_per_page' => $batch_size,
'offset' => $offset,
'fields' => 'ids',
'orderby' => 'ID',
'order' => 'ASC',
'no_found_rows' => true,
]);
foreach ($spots as $spot_id) {
// 1) Leggi il valore corrente (formato “raw” → third param FALSE)
$value = get_field($acf_field, $spot_id, false);
// Se è vuoto non serve forzare nulla
if ($value === null || $value === '' || $value === []) {
echo " • Post {$spot_id}: empty, go on\n";
continue;
}
// 2) Svuota il campo TEMPORANEAMENTE
delete_field($acf_field, $spot_id); // rimuove sia meta che cache
// oppure: update_field($acf_field, null, $spot_id);
// 3) Riscrivi il valore originale ⇒ trigger completo degli hook
update_field($acf_field, $value, $spot_id);
$total++;
echo " • Post {$spot_id}: update \n";
}
$offset += $batch_size;
} while (!empty($spots));
echo "\n {$total} posts done.\n";
@beee
Could you share your solution?
The paste-bin code seems incomplete.
Thanks.