I finished crafting this script.
I used Mohammed's script as a base, elaborated it a bit and made it ready for more cases.
Here is how you have to proceed on your own site (I have tested this process twice locally on the first duplicator we received):
1. Create a backup of your site (even if you tested this before on a staging site)
2. Put your site in maintenance mode. It is crucial that no one will call or reach this site during the process, more important even, no one must create any new post or save any field at this time. The site, in this time, should be accessed only by you.
3. Enable Theme Twenty Seventeen
4. In my tests, I had Toolset only enabled (Views and Types latest stable editions). I suggest you do the same.
5. Update your system (If it is required). Every active Plugin must be updated, as well as the active Theme and WordPress itself
6. Upload this file to the Twenty Seventeen Theme (to the main folder, where index.php and single.php are as well):
https://drive.google.com/file/d/1f2riNaINTqKjRoixiZEj0l4lFj5Wlu0b/view?usp=sharing
- this is a page template
- it has a unique name, you can change that as you wish, but the ending must be ".php"
- the current code in the file is as well commented, you will see that I apply the code to one post type and 2 fields:
Artist, wpcf-music-genre and wpcf-instruments.
These things are defined in 2 variables:
$affected_post_type (one post type a time only)
$affected_custom_fields_meta_keys (several fields connected to above post type)
These are the only 2 variables you will ever edit in this code.
- The Script can be used for ONE post type a time, but SEVERAL Fields (assigned to the same type) at once.
- Only checkboxes fields which saved 0 should be passed in the script.
- In the uploaded file, the script is ready to fix the issue for post type "Artist" and fields "wpcf-music-genre, wpcf-instrument"
- If you have more such fields (checkboxes that saved 0) please add them to the comma-separated list
- for any other post type, please change the $affected_post_type variable in the script and the affected_custom_fields_meta_keys if needed, and re-run the script
7. To actually run the script, I made it very safe.
- You need to create a page (after you uploaded the file to the theme)
- In the page Attributes of the new page, choose the Page template that will appear (name: "Fix It Page")
- save the page
==> As soon you will visit this page on the front end the script will run.
- after running the script, for safety reasons remove the page or disconnect the template
8. Remove the File from the server if needed
9. Head to the Custom Fields you updated during the above steps and immediately save them to "When unchecked, don't save anything to the database"
Please first test this to confirm it works.
Then, even if tested, perform the steps on live sites only after you made sure to have a backup.
It is crucial that you change the Field settings as described in #9, BEFORE you re-open the site for business, so the new posts will all be saved with correct values.
As for if this breaks anything, i did not see that you rely on this 0 value anywhere, so I have great hopes that this is all you need to do.
What I saw thou is you have several checkboxes fields (in other field groups).
In those cases, you would need to re-run the code, after editing the file I submitted you as instructed in #6 above.
Please let me know if there is any issue left.