Last active
November 6, 2024 11:54
-
-
Save vadimkantorov/f3ab7fa3170f7bc197eaee3d3b141da6 to your computer and use it in GitHub Desktop.
Primer of batch-exporting and batch-importing options from WordPress using wp-cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/wp-cli/entity-command/issues/512 | |
# https://developer.wordpress.org/cli/commands/option/list/ | |
# https://developer.wordpress.org/cli/commands/option/update/ | |
# export options to a pretty-formatted JSON file | |
wp option list --format=json | jq '.' > wpoptionimpex.json | |
# [ | |
# { | |
# "option_name": "name1", | |
# "option_value": "value1" | |
# }, | |
# { | |
# "option_name": "name2", | |
# "option_value": "value2" | |
# } | |
# ] | |
# import options from a JSON file | |
jq -r '.[] | [ (.option_name | @json), (.option_value | @json) ] | @tsv' wpoptionimpex.json | xargs wp option update --format=json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment