Common operations CLI WordPress commands

·

·

This is a list that I will be updating of the most common operations I perform with WordPress CLI. What is WP CLI? It is the execution of WordPress commands in a console.

Reasons for using WordPress CLI

.

Why use WordPress CLI? Using the command line is usually done is because there are certain operations that can take a long time and over the web would not be possible due to the time-out.

This happens especially on web pages with thousands of posts and when there are image operations.

List of CLI WordPress Commands

.

Database backup

.
wp db export

User management: creation and listing

.

Useful when you have console access, but have not yet been given WordPress access. It’s happened to us more than once

.

wp user create davidperez david@close.marketing --role=administrator

Official documentation: wp user create

List users:

wp user list
.

Official documentation: wp user list

Importing XML content

.

Importing entries with XML with wp import. EYE use export before so that it also includes featured images with this plugin.

wp import example.wordpress.2016-06-21.xml --authors=create
.

Regenerate thumbnail images

.
wp media regenerate
.

Official documentation: wp media regenerate

Delete blog posts before a date

.
wp post delete $(wp post list --post_type='post' --date_query='before=2021-01-01' --format=ids)
wp post list --post_type='post' --before="2021-01-01T00:00:00:00"
wp post list --before="2020-12-31T00:00:00:00"

Make a user Super admin

.
wp super-admin add closemarketing
.

Change password to a user

.
wp user update USER --user_pass=###

Leave a Reply

Your email address will not be published. Required fields are marked *