Home › Forums › Backend Issues (wp-admin) › Support for "Legacy" Fields › Reply To: Support for "Legacy" Fields
Unfortunately, this seems to do nothing. I’ve tried several fields, individual values, duplicate values, old_names and new_names, but nothing changes.
Hm. I hope I’m not stuck with Magic Fields.
I’ve got an old field, “basic_info_date”, which I’ll try to convert to a new field, “date”.
add_filter('acf/load_value/name=basic_info_date', '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, 'date', false);
if (!empty($old_value)) {
$value = $old_value;
}
return $value;
}
This displays the Unix base time in 1970 as the date, because the value is null:
echo '<p>';
echo date('l, F j, Y', strtotime(get_field('date')));
echo ' at ';
echo get_field('time');
echo "<br />\n";
The time shows up OK because I have a default value set.
When I modify the field names, am I breaking something? Do I need to erase the group and start over?
I’m really baffled.
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!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.