Skip to main content
TrustServers Knowledge Base

Tip: Start typing to get instant search results.

Table of Contents

Useful wp-cli Examples for WordPress

WP-CLI (WordPress Command Line Interface) is a powerful tool that allows you to manage WordPress sites directly from the command line (shell / SSH), without the need to use the WordPress admin graphical interface. It is an essential tool for professional WordPress administrators who want efficient and fast management of their sites.

Why should I use WP-CLI?

WP-CLI offers significant advantages for administrators and developers, such as:

  • Speed: Many tasks are completed much faster through the shell
  • Automation: Enables process automation (e.g., through scripts), making your work easier for numerous repetitive tasks
  • Bulk actions: Allows managing multiple sites simultaneously
  • Reliability: Provides immediate error feedback during operations, which you can also utilize in your scripts if desired

What do I need to run WP-CLI?

On all our hosting plans with SSH, you’ll find WP-CLI pre-installed. To run WP-CLI, simply connect to your hosting via SSH, navigate to the directory where your WordPress is installed, and execute the wp command.

Example:

cd public_html/
wp --help

Useful WP-CLI Examples

Updating WordPress

wp core update

This command:

  • Automatically checks for new WordPress versions
  • Downloads and installs the latest available version on your site
  • Keeps your site updated with the latest security updates

Recommended practice: Always backup before upgrading. You can check first for available updates with the wp core check-update command.

Installing and Activating a Theme

wp theme install twentytwentyfive

With this command:

  • You download themes directly from the official WordPress repository. Here for example the theme named twentytwentyfive (the theme slug is sufficient)
  • The theme is installed in the wp-content/themes/ folder

To activate the new theme in WordPress, simply run the following command:

wp theme activate twentytwentyfive

Note: You can install and activate the theme simultaneously with a single command:

wp theme install twentytwentyfive --activate

Installing and Activating a Plugin

wp plugin install wordpress-seo --activate

This command:

  • Downloads the plugin from the WordPress repository (we use the plugin slug as an argument)
  • Installs it in the wp-content/plugins/ folder
  • Activates it with the --activate parameter

Examples:

# Installation without activation
wp plugin install contact-form-7

# Installing a specific version
wp plugin install wordpress-seo --version=21.0

Updating a Plugin

wp plugin update wordpress-seo

Updates the specific plugin to the latest available version.

Creating a New Post or Page

wp post create --post_type=post --post_title='The article title' --post_content='Article content here' --post_status=publish

Creates a new post with the parameters you define:

  • --post_type: Content type (post, page, custom post type, etc.)
  • --post_title: Post title
  • --post_content: The article content
  • --post_status: Publication status (publish, draft, pending)
  • --post_author: Author ID in the system

Similarly, you can create a page as follows:

wp post create --post_type=page --post_title='About us' --post_status=publish

 

Deleting a Post

wp post delete 123

Permanently deletes the post with the specified ID.

Attention: The deletion is permanent. For safety, you can:

  • Move to “Trash” first: wp post update 123 --post_status=trash
  • Confirm the ID before deletion: wp post get 123

 

Additional Useful WP-CLI Examples

Below we present more examples. For safer use, you can create a backup before WP-CLI commands that will cause significant changes and/or use the --dry-run parameter for “preview” (dry-run doesn’t actually apply changes, but shows you what it would do).

Managing WordPress Plugins

# Deactivate plugin
wp plugin deactivate wordpress-seo

# Deactivate all plugins
wp plugin deactivate --all

# List all plugins
wp plugin list

# Delete plugin
wp plugin delete wordpress-seo

# Update all plugins
wp plugin update --all

# Update multiple plugins simultaneously
wp plugin update wordpress-seo contact-form-7

# Check available updates without installation
wp plugin list --update=available

Database Management

# Export database
wp db export backup.sql

# Import database
wp db import backup.sql

# Search and replace in database
wp search-replace 'old-domain.com' 'new-domain.com'

Flushing WordPress Cache

wp cache flush

User Management

# Update user password
wp user update demo_user --user_pass='MyNewP@ssw0rd123'

# List all users
wp user list

The commands presented are just a brief introduction to WP-CLI’s capabilities. The tool offers hundreds of commands for almost every aspect of WordPress management. With proper use, WP-CLI can save significant time every day and make managing multiple WordPress sites much more efficient.

Useful links

 

Was this article helpful?
Please Share Your Feedback
Πώς μπορεί να βελτιωθεί το άρθρο;
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.