Hi,
Thanks for getting in touch.
There is no change in our plugin but I think there are some changes in WooCommerce. To resolve this issue, you can add the prefix before the ID of the meta box and custom fields, like this
$prefix = 'mb_';
//Looper igennem farverne og viser en box til hver farve
foreach($farver as $farve){
$meta_boxes[] = [
'title' => "Tilføj billeder af " . $farve->name,
'id' => $prefix . $farve->slug,
'post_types' => ['product'],
'context' => 'normal',
'priority' => 'high',
'fields' => [
[
'type' => 'image_advanced',
'id' => $prefix . $farve->slug,
'name' => 'Tilføj billeder',
'max_status' => false,
],
],
];
}
Hi Neo,
Thanks for a quick reply. However, we have thousands of fields with the old ID structure. How do we fix the old fields?
Hi,
You can follow this article to know how to change the field ID on your site https://metabox.io/changing-meta-box-field-id/?swcfpc=1
Hi Neo,
Now I am back from holiday and I have changed the code.
I am sorry to say that adding a prefix to the ID does not help.
The new code is here: https://pastebin.com/rRCvjJ4H and it does not work either.
Hi,
Hmm, not sure why it does not work on your site. Another way, please change the code to get the post ID with this one
$post_id = null;
if ( isset( $_GET['post'] ) ) {
$post_id = intval( $_GET['post'] );
} elseif ( isset( $_POST['post_ID'] ) ) {
$post_id = intval( $_POST['post_ID'] );
}
Let me know how it goes.
Wauw… Changing $post_id = false; to $post_id = null; did the trick even though the ID is without prefix. I do not understand how that helped. Do you?
Can I keep the ID without prefix if it works?
Hi,
Yes, if changing the post ID works on your site, you can keep the current ID without using the prefix. Not sure why this does not work on your end but you can read the difference between false and null here https://stackoverflow.com/questions/137487/null-vs-false-vs-0-in-php