When using command line applications, like WP-CLI, you may run into a scenario where you’re attempting to pass too much information via arguments. That will result in an error like zsh: argument list too long: wp
or /usr/local/bin/wp: Argument list too long
. Similar to website URLs, there is a maximum length a command can be. These maximum lengths will vary by computer.
Good news, these limitations can be worked around using HereDocs instead of arguments.
Recently, I ran into this argument limitation while attempting to use wp post meta update
with a very large piece of data. I overcame the argument limitation using here documents which will instead stream it to the command. This same approach can be applied for other use cases. Here are a few examples using HereDocs with WP-CLI.
Deletes massive list of posts IDs.
wp post delete --prompt << heredoc
$(wp post list --format=ids)
heredoc
Updates post meta with contents of a massive json file.
wp post meta update 123 custom_field << heredoc
$(cat massive.json)
heredoc
Or similar, updates post meta with contents of a massive bash variable.
wp post meta update 123 custom_field << heredoc
$json
heredoc
Reference: WP-CLI issue #3607