Support

Account

Home Forums General Issues Date Time Field Not Storing Value Reply To: Date Time Field Not Storing Value

  • @bocacommunity

    Yes, you have a problem.

    1 is that the other field is not supported and 2 is that if you add a field in ACF it will not have the same field key.

    You can create a temporary function that runs and replaces the data, the problem is that it might time out. I might do something like this (back up your database first)

    
    add_action('init', 'temp_replace_data_function') {
      if (!is_admin()) {
        // only run in the admin
        return;
      }
      $args = array(
        // just a sample
        // do query to get all posts that have the old field
        'post_type' => 'post type to update',
        'posts_per_page' => -1,
        'meta_query' => array(
          array(
            // only get posts that have a value for this field
            // this way we can eliminate the ones we've already done
            // if it times out, re-running will not redo posts we've already taken care of
            'key' => 'old-field-name',
            'compare' => 'EXISTS'
          )
        ),
        // other arguments as needed
      );
      $query = new WP_Query($args);
      if ($query->have_posts()) {
        global $post;
        while ($query->have_posts()) {
          $query->the_post();
          $post_id = $post->ID;
          // get the old value
          // convert it from what the other plugin is storing to ACF format
          // update the new ACF field (use the field key, not field name)
          // sorry I can't be much more help here
          
          // **** IMPORTANT ****
          // delete the post meta for the old field name
          // see not in the meta query above
          delete_post_meta($post_id, 'old-field-name');
        }
      }
    }