HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/school/wp-content/themes/school/fix-acf.php
<?php
require_once( dirname(__FILE__) . '/../../../../wp-load.php' );

$field_name = 'online-option'; // change this to your ACF field name
$post_type  = 'product';

$posts = get_posts([
  'post_type'      => $post_type,
  'posts_per_page' => -1,
  'post_status'    => 'any',
]);

foreach ($posts as $post) {
    $value = get_field($field_name, $post->ID, false);

    if (is_array($value)) {
        $cleaned = array_map(function($v) {
            // Remove "value:" if present
            if (strpos($v, ':') !== false) {
                return trim(explode(':', $v, 2)[1]);
            }
            return trim($v);
        }, $value);

        update_field($field_name, $cleaned, $post->ID);
        echo "✅ Cleaned post ID {$post->ID}<br>";
    }
}

echo "<strong>Done.</strong>";