Skip to content

Instantly share code, notes, and snippets.

@cr0ybot
Created March 9, 2022 13:50
Show Gist options
  • Save cr0ybot/b6eb06265ad974de09bbae0c828a3e81 to your computer and use it in GitHub Desktop.
Save cr0ybot/b6eb06265ad974de09bbae0c828a3e81 to your computer and use it in GitHub Desktop.
Update past Ninja Forms submission values to match changes in the form
# Had to deal with changing years worth of Ninja Forms submissions to match tweaks in the live form values a lot lately.
# There may be a "better" way to do this using Ninja Forms' "API", but running some SQL via phpmyadmin is quicker and doesn't require deploying code.
# You can inspect the field in the form builder to find the field ID, which will be in a `data-id` attribute. The `meta_key` is the field ID formatted like this: "_field_###".
# For Radio List fields, there is only a single value.
# If you're changing numerical values, be sure to start on one end so you don't end up changing values that were just changed by the previous step.
UPDATE wp_postmeta SET meta_value='0' WHERE meta_key='_field_200' AND meta_value='1';
UPDATE wp_postmeta SET meta_value='1' WHERE meta_key='_field_200' AND meta_value='2';
# For Checkbox List fields, the values are stored as serialized arrays. It means instead of just SETing we have to REPLACE.
# You have to target the full value along with the string type indicator and length. That means whaterver you replace it with must also include the string type indicator and langth!
UPDATE wp_postmeta SET meta_value=REPLACE(meta_value, 's:10:"some-value"', 's:1:"0"') WHERE meta_key='_field_201';
UPDATE wp_postmeta SET meta_value=REPLACE(meta_value, 's:16:"some-other-value"', 's:1:"1"') WHERE meta_key='_field_201';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment