-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A way to convert wpalchemy fields to acf fields? #122
Comments
Hi, @stratboy, any luck with the fields migration to ACF? |
Yes. First, backup your DB. Very important. The following functions are good for string data (should be the vast majority). They don't work for images. for images, I solved making acf text fields containing copy of old wpalchemy image data, meant to be used only for existing data, and creating new acf fields meant to be used for new data. Then it's quite easy to rapidly check for new||old data in your php templates. Hope it helps. // To convert fields: function lr_migrate_meta_fields($field, $custom_key = false, $unique = true, $check = false, $delete_old = false){
if(!is_admin()) return false;
if($check){
if(get_option($check)) return false;
}
global $wpdb;
$metas = $wpdb->get_results(
"
SELECT *
FROM $wpdb->postmeta
WHERE meta_key = '$field'
"
);
foreach($metas as $meta){
$fields_data = unserialize($meta->meta_value);
foreach($fields_data as $key => $value){
// $unique is for avoiding the same field gets written more than once
$k = ($custom_key) ? $custom_key : $key;
add_post_meta($meta->post_id, 'acf_' . $k, $value, $unique);
}
}
if($check) add_option($check, 1);
} To delete olds: function lr_delete_meta_fields($field){
if(!is_admin()) return false;
global $wpdb;
$metas = $wpdb->get_results(
"
SELECT *
FROM $wpdb->postmeta
WHERE meta_key = '$field'
"
);
foreach($metas as $meta){
delete_post_meta($meta->post_id, $meta->meta_key);
}
} |
Thank you @stratboy, it worked like a charm :) |
Hi, since this plugin is no more maintained, since years ago, and since the way it stores meta values is not standard/flat, I'm starting having A LOT of problems with websites built with wpalchemy and no more usable with php 8, and having to convert all the wpalchemy fields to acf fields, preserving their values.
Not that simple. It would be great if the developer could give us a function, or a simple way, to accomplish this task. It it possible please?
Thank you, regards
The text was updated successfully, but these errors were encountered: