Support

Account

Home Forums Backend Issues (wp-admin) Support for "Legacy" Fields Reply To: Support for "Legacy" Fields

  • A post object field that allows multiple selections, or a relationship field, both work basically the same way, it’s really only the interface that’s different.

    Basically this is what you’d need to do. Let’s just say that the old field was named “old_field” and the new one is named “new_field”. You create an acf/load_value filter for the new ACF field, information can be found here https://www.advancedcustomfields.com/resources/acfload_value/

    
    add_filter('acf/load_value/name=new_field', 'convert_old_field_to_acf', 10, 3);
    function convert_old_field_to_acf($value, $post_id, $field) {
      if ($value !== NULL) {
        // if the value is not set for ACF yet
        // then the value will be NULL
        // if the current value is not NULL
        // then return because the field already
        // had been set
        return;
      }
      // get value from old field
      $old_value = get_post_meta($post_id, 'old_field', false);
      if (!empty($old_value)) {
        $value = $old_value;
      }
      return $value;
    }
    

    Using a filter like this you can leave all the old values where they are, they will be returned for use is ACF function and eventually all of the data will be move over as posts are edited so you don’t need to go an convert everything ahead of time.