Table of Contents
Install
Installation instruction:
https://wp-cli.org/#installing
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
To test the installation:
wp --info
Commands
- Each command starts with: wp
- Next you need to use a sub-command such as core, theme, plugin, and…
- Then use a sub-command for the sub-command like install
- The last section of the command is option
wp theme install twentytwentyone
Installing Twenty Twenty-One (1.8)
Downloading installation package from https://downloads.wordpress.org/theme/twentytwentyone.1.8.zip...
Unpacking the package...
Installing the theme...
Theme installed successfully.
Success: Installed 1 of 1 themes.
Resources
- WP-CLI Handbook
- wp help command in Terminal
wp help
wp help theme
wp help theme install
To exit the list of commands in help command, just press q key.
wp core
wp core version
wp core version --extra
wp core update
wp core update --version=5.5.3
wp core update --version=5.5.3 --force
wp core update --locale=au
Update Error
wp option delete core_updater.lock
wp core multisite-convert
wp theme
wp theme status
wp theme delete twentytwentyone twentytwentytwo
wp theme search blog
wp theme install astra
wp theme install https://downloads.wordpress.org/theme/astra.4.7.3.zip
wp theme activate astra
wp theme update astra
wp theme update --all
wp theme mod list
wp plugin
wp plugin status
wp plugin get elementor
wp plugin toggle gutenberg
wp plugin deactivate --all
wp plugin serarch SEO
wp plugin install seo-by-rank-math
wp plugin activate seo-by-rank-math
wp plugin uninstall akismet
wp sidebar & wp widget & wp menu
wp sidebar list
wp widget list
wp widget list sidebar-1
wp widget add calendar sidebar-1
wp widget move calendar-1 --position=1 --sidebar-id=sidebar
wp menu create Footer
wp menu location list
+-------------+-------------------+
| location | description |
+-------------+-------------------+
| topbar_menu | Top Bar |
| main_menu | Main |
| footer_menu | Footer |
| mobile_menu | Mobile (optional) |
+-------------+-------------------+
wp menu list
+---------+--------+--------+-----------+-------+
| term_id | name | slug | locations | count |
+---------+--------+--------+-----------+-------+
| 5 | Footer | footer | | 0 |
+---------+--------+--------+-----------+-------+
wp menu location assign footer footer_menu
wp menu item add-custom footer "Privacy Policy" https://hoomaan.dev
wp post-type
wp post-type list
wp post-type get e-landing-page
wp post
wp post list
wp post list --posts_per_page=10
wp post list --post_type=page
wp post get 6
wp post create --post_title='Why WP-CLI is Great!'
wp post generate --count=10
curl -N https://loripsum.net/api/5 | wp post generate --post_content --count=10
wp comment
wp comment
wp comment list --number=25
wp comment list --status=hold
wp comment list --status=hold --fields=comment_ID,comment_content
wp comment spam $(wp comment list --status=hold --format=ids)
wp comment approve $(wp comment list --status=hold --format=ids)
wp comment unspam 1
wp comment count
approved: 1
spam: 0
trash: 0
post-trashed: 0
all: 1
moderated: 0
total_comments: 1
wp help comment delete
wp comment delete $(wp comment list --status=spam --format=ids) --force
wp taxonomy | wp term
wp taxonomy list
wp taxonomy list --public=1
wp term list category
wp term create post_tag wpcli
wp term list post_tag
+---------+------------------+-------+-------+-------------+--------+-------+
| term_id | term_taxonomy_id | name | slug | description | parent | count |
+---------+------------------+-------+-------+-------------+--------+-------+
| 6 | 6 | wpcli | wpcli | | 0 | 0 |
+---------+------------------+-------+-------+-------------+--------+-------+
wp term update post_tag 6 --name=WP-CLI
wp term list post_tag
+---------+------------------+--------+-------+-------------+--------+-------+
| term_id | term_taxonomy_id | name | slug | description | parent | count |
+---------+------------------+--------+-------+-------------+--------+-------+
| 6 | 6 | WP-CLI | wpcli | | 0 | 0 |
+---------+------------------+--------+-------+-------------+--------+-------+
wp term migrate 6 --from=post_tag --to=category
wp post list --category_name=wp-cli
wp media
wp media image-size
wp media regenerate --only-missing --yes
wp post list
+----+----------------------+----------------------+---------------------+-------------+
| ID | post_title | post_name | post_date | post_status |
+----+----------------------+----------------------+---------------------+-------------+
| 79 | Post 9 | post-9 | 2024-08-11 15:33:16 | publish |
| 80 | Post 10 | post-10 | 2024-08-11 15:33:16 | publish |
| 81 | Post 11 | post-11 | 2024-08-11 15:33:16 | publish |
| 74 | Post 4 | post-4 | 2024-08-11 15:29:39 | publish |
| 75 | Post 5 | post-5 | 2024-08-11 15:29:39 | publish |
| 76 | Post 6 | post-6 | 2024-08-11 15:29:39 | publish |
| 77 | Post 7 | post-7 | 2024-08-11 15:29:39 | publish |
| 78 | Post 8 | post-8 | 2024-08-11 15:29:39 | publish |
| 73 | Why WP-CLI is greate | | 2024-08-11 15:23:52 | draft |
| 7 | Another Awesome Post | another-awesome-post | 2024-03-07 11:20:18 | publish |
| 6 | Awesome Post | awesome-post | 2024-03-07 11:20:01 | publish |
| 1 | Hello world! | hello-world | 2024-03-06 15:16:55 | publish |
+----+----------------------+----------------------+---------------------+-------------+
wp media import https://images-assets.nasa.gov/image/20060918_exp14_12/20060918_exp14_12\~large.jpg --post_id=73 --featured_image
wp media import /Users/hoomaan/Documents/Projects/hoomaan.dev/Assets/*.png
wp role
wp role list
+---------------+---------------+
| name | role |
+---------------+---------------+
| Administrator | administrator |
| Editor | editor |
| Author | author |
| Contributor | contributor |
| Subscriber | subscriber |
| Translator | translator |
+---------------+---------------+
wp cap list subscriber
read
level_0
wp cap list subscriber | sort
level_0
read
wp role create proofreader Proofreader --clone=editor
wp cap remove proofreader delete_published_pages delete_published_posts edit_published_pages edit_published_posts publish_pages publish_posts
wp cap add proofreader dewnload_posts download_pages
wp role reset author
wp user
wp user list
wp user create monarch monarch@hoomaan.dev --role=proofreader
Success: Created user 3.
Password: TQYt8JyQVlOQ&^H2h5dDV3)6
wp user reset-password monarch
Reset password for monarch.
Success: Password reset for 1 user.
wp user get monarch
+-----------------+---------------------+
| Field | Value |
+-----------------+---------------------+
| ID | 3 |
| user_login | monarch |
| user_email | monarch@eden.bz |
| user_registered | 2024-08-12 10:53:56 |
| display_name | monarch |
| roles | proofreader |
+-----------------+---------------------+
wp user list-caps monarch | sort
wp role create bronze Bronze --clone=subscriber
Success: Role with key 'bronze' created. Cloned capabilities from 'subscriber'.
wp role create silver Silver --clone=subscriber
Success: Role with key 'silver' created. Cloned capabilities from 'subscriber'.
wp role create gold Gold --clone=subscriber
Success: Role with key 'gold' created. Cloned capabilities from 'subscriber'.
wp user generate --count=5 --role=bronze | wp user generate --count=5 --role=silver | wp user generate --count=5 --role=gold
Generating users 100% [===========================================] 0:00 / 0:00
wp user import-csv /Users/list/users.csv
wp user meta list monarch
+---------+-----------------------+-------------------------------+
| user_id | meta_key | meta_value |
+---------+-----------------------+-------------------------------+
| 3 | nickname | monarch |
| 3 | first_name | |
| 3 | last_name | |
| 3 | description | |
| 3 | rich_editing | true |
| 3 | syntax_highlighting | true |
| 3 | comment_shortcuts | false |
| 3 | admin_color | fresh |
| 3 | use_ssl | 0 |
| 3 | show_admin_bar_front | true |
| 3 | locale | |
| 3 | wp_capabilities | a:1:{s:11:"proofreader";b:1;} |
| 3 | wp_user_level | 7 |
| 3 | dismissed_wp_pointers | |
+---------+-----------------------+-------------------------------+
wp user meta update monarch first_name 'Monarchy'
wp user meta delete monarch first_name
wp user meta update monarch articles_proofed 47
[–role=<role>]: The role of the user to create. Default: default role. Possible values include ‘administrator’, ‘editor’, ‘author’, ‘contributor’, ‘subscriber’.
wp option
wp option list
wp option list --search=rss
+-------------+--------------+
| option_name | option_value |
+-------------+--------------+
+-------------+--------------+
wp option list --search="*rss*"
+-----------------+--------------+
| option_name | option_value |
+-----------------+--------------+
| posts_per_rss | 10 |
| rss_use_excerpt | 0 |
| widget_rss | a:0:{} |
+-----------------+--------------+
wp option update posts_per_rss 300
wp option get posts_per_rss
wp option get siteurl
wp option add posts_to_proof 7
wp option delete posts_to_proof
wp option pluck theme_mods_oceanwp nav_menu_locations
array (
'footer_menu' => 5,
)
wp option patch
wp cache | wp transient | wp rewrite | wp embed
wp cache flush
wp transient list
wp transient delete --all
wp rewrite list
wp rewrite flush
wp embed fetch https://youtu.be/3VnLZEttL4s
wp embed cache clear 434
wp db
wp db prefix
wp db size
wp db tables
wp db tables --all-tables
wp db columns wp_posts
wp db query "SELECT ID, post_title, post_date FROM wp_posts WHERE post_type='post' ORDER BY ID DESC LIMIT 0,20"
wp db columns wp_postmeta
wp db query "SELECT ID, post_title, meta_key, meta_value FROM wp_posts INNER JOIN wp_postmeta ON ID = post_id WHERE post_type='post' ORDER BY ID DESC LIMIT 0, 20"
wp db query "SELECT wp_comments.comment_id, comment_approved, meta_key, meta_value FROM wp_comments INNER JOIN wp_commentmeta ON wp_comments.comment_ID = wp_commentmeta.comment_ID WHERE comment_approved='spam' LIMIT 0,10"
wp db query "DELETE wp_comments, wp_commentmeta FROM wp_comments INNER JOIN wp_commentmeta ON wp_comments.comment_ID = wp_commentmeta.comment_ID WHERE comment_approved='spam'"
wp db cli
mysql> SELECT ID, post_title FROM wp_posts WHERE post_type='pst' AND post_status='publish' ORDER BY ID DESC LIMIT 0,25;
wp db search
wp db search wp-cli --all-tables
Maintaining database
wp db optimize
wp db repair
wp db clean
wp db reset
wp db clean
wp db tables
wp config set table_prefix wp_123_
wp core install
Exporting, Importing, Search, and Replace
wp db export wpcli.sql
scp wpcli.sql /Users/xxx/Local Sites/wp-dev/app/public
scp /Users/xxx/Local Sites/wp-dev/app/public/wpcli.sql ./
wp db import wpcli.sql
wp db search-replace https://wpcli.local https://hoomaan.local
wp option get siteurl
Installing WordPress with WP-CLI
wp core download
wp core config --dbname=fjdlfjdfdlsjf --dbuser=dfkjdsfjds --dbpass=dlfkjdslfjdsjlf
wp core install --url=hoomaan.dev/wpcli/ --title="Hoomaan WP-CLI" --admin_user=Hoomaan --admin_email=dev@hoomaan.dev
Advanced WP-CLI commands
wp eval-file
wp scaffold
cd wp-content
cd plugins/
mkdire cli-plugin
wp scaffold plugin my-great-plugin