1

I want to create a script that adds WordPress options in a fresh WordPress installation using WP-CLI.

I ran this command wp option list --format=json | jq -c -M '.[]'

The output of the command like this:

{"option_name":"siteurl","option_value":"http://wp.test"}
{"option_name":"home","option_value":"http://wp.test"}

So how to iterate over each object and run add command and passing key and value as an argument like this wp option add $option_name $option_value?

Nurdindev
  • 173
  • 1
  • 12

1 Answers1

2

One approach: Use jq to build the wp commands and execute them in your shell:

source <(wp option list --format=json |
         jq -r '.[] | "wp option add \"\(.option_name)\" \"\(.option_value)\""')
Shawn
  • 47,241
  • 3
  • 26
  • 60