How to install
Use curl to download the WP-CLI phar file:
1
2
| curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
|
Check if the file is executable:
1
2
| php wp-cli.phar --info
|
Move the downloaded file to a directory in your system’s PATH (e.g., /usr/local/bin/):
1
| sudo mv wp-cli.phar /usr/local/bin/wp
|
Make it executable:
1
| sudo chmod +x /usr/local/bin/wp
|
test install
Create child theme
1
| wp scaffold child-theme sample-theme --parent_theme=twentysixteen
|
Content Commands
1
| wp post create --post_type=page --post_title="Your Page Title" --post_content="Your page content goes here." --post_status=publish
|
Database commands
Delete database
This command drops the database. No name is required as wpcli looks in the wp-config file to find the database name. You can run this command from anywhere within your Wordpress file structure.
Export database
Will export an SQL file to your Wordpress root directory.
Export database into custom named file
The default will be to use the database name
1
| wp db export custom_filename.sql
|
Import database
Ensure to provide the correct path to the file.
1
| wp db import wordpress_dbase.sql
|
Search and Replace database
Find all occurences of a string in a database and replace it with another value. This can be really useful when you are migrating a site to a different domain.
1
| wp search-replace 'http://example.test' 'http://example.com'
|
Plugin commands
List plugins
Delete plugin
1
| wp plugin delete akismet
|
Install Plugin
Here we install the query monitor plugin
1
| wp plugin install query-monitor
|
Update All Plugins
Update WP Core
Flush the Permalinks
User commands
Create a wp user account
1
| wp user create bob bob@example.com --role=author
|
Get the ID of the user
This command is important for running other user related functions that take the user id as a requirement.
Update the password of the user
Once you have the user ID then you can update the users password
1
| wp user update 7 --user_pass=new_pass
|
Generate posts
Generate dummy / demo content
1
| wp post generate --count=10 --post_type=page --post_date=1999-01-04
|
Regenerate Image sizes
As you may already know Wordpress supports custom image sizes. Now when you add a new custom image size your site, you will need to regenerate the images so that your new custom image files in the new size exists.
1
| wp media regenerate --image_size=large
|
older gist
create user - password generated
wp user create your_username ex@example.com.au –role=administrator
wp gf field create 1 type label
wp gf form create ‘My Form Title’ ‘Description Here’
wp admin
Open /wp-admin/ in a browser.
wp cache
Adds, removes, fetches, and flushes the WP Object Cache object.
wp cap Adds, removes, and lists capabilities of a user role.
wp cli Review current WP-CLI info, check for updates, or see defined aliases.
wp comment Creates, updates, deletes, and moderates comments.
wp config Generates and reads the wp-config.php file.
wp core Downloads, installs, updates, and manages a WordPress installation.
wp cron Tests, runs, and deletes WP-Cron events; manages WP-Cron schedules.
wp db Performs basic database operations using credentials stored in wp-config.php. wp search-replace
A string to search for within the database. Replace instances of the first string with this new string. […] List of database tables to restrict the replacement to. Wildcards are supported, e.g. 'wp_*options' or 'wp_post*'. [--dry-run] Run the entire search/replace operation and show report, but don’t save changes to the database. wp dist-archive Create a distribution archive based on a project’s .distignore file. wp embed Inspects oEmbed providers, clears embed cache, and more. wp eval Executes arbitrary PHP code. wp eval-file Loads and executes a PHP file. wp export Exports WordPress content to a WXR file. wp find Find WordPress installations on the filesystem. wp help Get help on WP-CLI, or on a specific command. wp import Imports content from a given WXR file. wp language Installs, activates, and manages language packs. wp media Imports files as attachments, regenerates thumbnails, or lists registered image sizes. wp menu Lists, creates, assigns, and deletes the active theme’s navigation menus. wp network Perform network-wide operations. wp option Retrieves and sets site options, including plugin and WordPress settings. wp package Lists, installs, and removes WP-CLI packages. wp plugin Manages plugins, including installs, activations, and updates. wp plugin delete akismet wp plugin install query-monitor wp post Manages posts, content, and meta. wp post-type Retrieves details on the site’s registered post types. wp profile wp rewrite Lists or flushes the site’s rewrite rules, updates the permalink structure. wp role Manages user roles, including creating new roles and resetting to defaults. wp scaffold Generates code for post types, taxonomies, plugins, child themes, etc. wp search-replace Searches/replaces strings in the database. wp server Launches PHP’s built-in web server for a specific WordPress installation. wp shell Opens an interactive PHP console for running and testing PHP code. wp sidebar Lists registered sidebars. wp site Creates, deletes, empties, moderates, and lists one or more sites on a multisite installation. wp super-admin Lists, adds, or removes super admin users on a multisite installation. wp taxonomy Retrieves information about registered taxonomies. wp term Manages taxonomy terms and term meta, with create, delete, and list commands. wp theme Manages themes, including installs, activations, and updates. wp transient Adds, gets, and deletes entries in the WordPress Transient Cache. wp user Manages users, along with their roles, capabilities, and meta. //example wp user create instructor email@yoursite.com.au --role=instructor wp widget Manages widgets, including adding and moving them within sidebars. ## setup wordpress wp core download ## Troubleshooting If you are getting some errors when trying to update plugins it could be due to permissions. Some plugins also require a valid license to update. To fix a permission related issue. See the link below to reset the Wordpress file and directory permissions. [see wp file permissions commands](/posts/wordpress-file-permissions/) ## Switch to non root user If you have installed WpCLI on a webserver. Before running any wpcli commands you probably want to switch to a non-root so that you are not flagged with warnings when running these commands as `root`. ### Switch to non-root user ```bash su non-root ``` ## Install WordPress with WpCLI WpCLI Plays an important role when you installing WordPress on a barebones VPS. As there is no control panel there is no user interface for creating and installing the database. WpCLI steps into to help out and makes installation of Wordpress on a barebones VPS efficient and easy. [Install WordPress website on a VPS using WPCli](/posts/setup-wordpress-on-vps/) ## Official Documentation [WPCLI](https://wp-cli.org/){:target="\_blank"} installed