WP Cli – post add meta in xargs after wp post generate – add multiple fields

You just need to change the syntax of xargs to run multiple commands using the same placeholder:

wp post generate --format=ids --count=10 | sed -e "s/ /\n/g" | xargs -n1 -I % sh -c 'echo "Adding fields for %"; wp post meta add % foo bar; wp post meta add % key_2 value_2';

Update:

The output of wp post generate is post ids with spaces for the delimiter. I’m sure there is a better way for xargs to process spaces but I’m using sed to replace the spaces with newlines.

Reference: