Since I wanted to test how my plugin would function without data, I needed to clear some ACF created options from the database. ACF creates a whole bunch of options using a very similar name, in my case;
- options_mc_creator_mailchimp_api_key
- _options_mc_creator_mailchimp_api_key
- options_mc_creator_mailchimp_server
- And lots more..
I like using WP CLI for this but WP CLI doesn’t allow me to delete options by search. We can solve that though.
WP CLI allows searching for options
We can use this: wp option list --search='options_mc_creator'
Now, we just want the option_name:wp option list --fields='option_name' --search 'options_mc_creator'
And then get rid of the formatting by formatting as CSV:wp option list --fields='option_name' --search='options_mc_creator' --format=csv
Let’s feed the output of that command to the delete function:
wp option delete $(wp option list --fields='option_name' --search='options_mc_creator'
--format=csv
)
Boom! all done.
Leave a Reply