Home › Forums › ACF PRO › Force update of “Bidirectional” › Reply To: Force update of “Bidirectional”
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";
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.