Home › Forums › General Issues › Date Time Field Not Storing Value › Reply To: Date Time Field Not Storing Value
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');
}
}
}
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.