![]() ![]() Save the same statement to your ~/.bashrc or ~/.zshrc to always have it available. In this example, running alias creates a check-all alias for the current shell session. Run all three status check commands with one check-all alias. ![]() If you find yourself running the same commands quite often, you can define aliases to them for easier access. Top ↑ Define aliases, short macros to common commands $ wp user generate -count=5 -format=ids | xargs -0 -d ' ' -I % wp user meta add % foo bar In this example, wp user generate passes user ids to xargs, which splits the space-separated ids into a list and calls wp user meta add for each. Wp user generate only generates users it doesn’t perform supplemental operations. Success: Added 24 capabilities to 'author' role. $ wp cap list 'editor' | xargs wp cap add 'author' Note the | shell operator, which passes the results of wp cap list to xargs. Enter, xargs, whose default behavior is to split newline output into a space-separated list. However, wp cap list lists capabilities separated by newlines, and wp cap add only accepts space-separated capabilities. You may want to assign all editor capabilities to the author role. If you need a bit more flexibility, xargs lets you pass the output of one command to another command, while performing minor transformation on the output. $ wp post delete $(wp post list -post_type='page' -format=ids) In this example, $() lets us pass the space-separated page ids to wp post delete. $ wp post list -post_type='page' -format=idsĬombining wp post list with wp post delete lets you easily delete all posts. In this example, the command lists page ids as space-separated values. Wp post list only lists posts it doesn’t perform any operation on them. Composability is a key philosophy of WP-CLI, and there are two common approaches for composing commands.Ĭommand substitution passes the output of one command to another command, without any transformation to the output. In many cases, it can be extremely powerful to be able to pass the results of one command to another. Or another way to search history is grepping the output from the history command like: $ history | grep wpĪny of the commands found in that list can be re-executed by bang-number, so for example if the output says your desired command is #218, you just do !218 When ‘bck-i-search’ appears, your keystrokes will search against commands saved in your bash history. You Should Knowĭid you know that every command you run on your shell is saved to history? Search through your history with CTRL + R: $ wp core download -version=nightly -force Here are some of our favorite shell helper utilities. The project page is, you’ll find that a little bit of command line knowledge can have a huge impact on your workflow. Sort plugins or themes by certain column(s)Īs you advance upon your use of WP-CLI WP-CLI WP-CLI is the Command Line Interface for WordPress, used to do administrative and development tasks in a programmatic way.Change to a certain WordPress installation’s directory from a menu.Create a page from a file and flag it with the file name.Install and Configure WordPress with WP-CLI.Start wp-cli with ABSPATH in the current dir and under the current dir’s owner.Define aliases, short macros to common commands. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |