{"id":8435,"date":"2022-09-16T14:22:19","date_gmt":"2022-09-16T14:22:19","guid":{"rendered":"https:\/\/www.fastcomet.com\/blog\/?p=8435"},"modified":"2022-09-16T14:22:20","modified_gmt":"2022-09-16T14:22:20","slug":"wordpress-management-with-wp-cli","status":"publish","type":"post","link":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli","title":{"rendered":"10+ WP-CLI Tricks to Manage Your WordPress Site"},"content":{"rendered":"\n<p class=\"has-drop-cap\">WordPress is a fantastic project, but as with any piece of software, there may be times when you wish you had a backdoor into your code and database. You know what we&#8217;re talking about if you&#8217;ve ever attempted to reset your admin privileges using a faulty reset password link.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Fortunately, there is a workable option. With command-line access to your WordPress installation provided by <a href=\"https:\/\/wp-cli.org\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">The WP-CLI project<\/a>, you can control the majority of your website with a few simple terminal commands.<\/p>\n\n\n\n<p>For instance, you can easily update your password using the WP-CLI if your &#8220;reset password&#8221; link isn&#8217;t working. WP-CLI is useful in a variety of circumstances that are similar to each other. Additionally, we simply adore the hacker-like sensation that comes from using the command line.<\/p>\n\n\n\n<p>In this article, we&#8217;ll describe and demonstrate how to complete a few of the generally tedious chores that WP-CLI almost turns into a delightful experience. Let&#8217;s get to work!<\/p>\n\n\n\n<p><strong>Table of Contents:<\/strong><\/p>\n\n\n\n<ul class=\"nav-list\">\n\t<li><a href=\"#h-what-is-the-wp-cli-project\">What is the WP-CLI Project<\/a><\/li>\n\t<li><a href=\"#h-best-wp-cli-commands-to-manage-your-wordpress-site\">Best WP-CLI Commands to Manage your WordPress Site<\/a><\/li>\n\t<ul>\n\t<li><a href=\"#h-look-into-the-the-wp-config-php-file\">Look Into the the wp-config.php File<\/a><\/li>\n\t<li><a href=\"#h-run-core-updates\">Run Core Updates<\/a><\/li>\n\t<li><a href=\"#h-update-disable-and-delete-unwanted-plugins\">Update, Disable, and Delete Unwanted Plugins<\/a><\/li>\n\t<li><a href=\"#h-reset-user-passwords\">Reset User Passwords<\/a><\/li>\n\t<li><a href=\"#h-backup-and-manipulate-the-database\">Backup and Manipulate the Database<\/a><\/li>\n\t<li><a href=\"#h-clean-post-revisions\">Clean Post Revisions<\/a><\/li>\n\t<li><a href=\"#h-create-a-child-theme\">Create a Child Theme<\/a><\/li>\n\t<li><a href=\"#h-create-dummy-content-for-testing\">Create Dummy Content for Testing<\/a><\/li>\n\t<li><a href=\"#h-blank-your-site\">Blank Your Site<\/a><\/li>\n\t<li><a href=\"#h-reinstall-wordpress-core\">Reinstall WordPress Core<\/a><\/li>\n\t<li><a href=\"#h-remove-all-spam-comments\">Remove All Spam Comments<\/a><\/li>\n\t<li><a href=\"#h-tame-wp-cron\">Tame wp-cron<\/a><\/li>\n\t<li><a href=\"#h-get-help-on-any-wp-cli-command\">Get Help on Any WP-CLI Command<\/a><\/li>\n\t<\/ul>\n<\/ul>\n\n\n\n<h2 class=\"h3 wp-block-heading\" id=\"h-what-is-the-wp-cli-project\">What is the WP-CLI Project<\/h2>\n\n\n\n<p>Since this application allows you command-line access to the WordPress administrative system, WP-CLI stands for WordPress Command-Line.<\/p>\n\n\n\n<p>On August 8th, 2018, <a href=\"https:\/\/www.fastcomet.com\/blog\/wp-cli-v2\" target=\"_blank\" rel=\"noreferrer noopener\">WP-CLI v2<\/a> was released. If you&#8217;re a FastComet customer, WP-CLI v2.0+ is already installed by default on all of our servers. To get started, just SSH into your server. You can be sure that all of <a href=\"https:\/\/www.fastcomet.com\/kb\/free-ssh-access-with-all-hosting-packages\" target=\"_blank\" rel=\"noreferrer noopener\">our hosting plans include SSH access<\/a>.<\/p>\n\n\n\n<p>Typically, managing a WordPress website manually requires using the online user interface (the wp-admin). Consequently, fixing a malfunctioning site or overseeing a transitional time frequently entails sifting through files using an <a href=\"https:\/\/www.fastcomet.com\/tutorials\/ftp\" target=\"_blank\" rel=\"noreferrer noopener\">FTP client<\/a> or attempting to write original PHP code. WP-CLI eliminates the need for additional plugins and streamlines the process of managing your website by providing a direct-access shortcut.<\/p>\n\n\n\n<p>There is a slight learning curve if you have never used the command line before. WP-CLI, however, can greatly speed up how you deal with your website once you get started. With only a few clicks, you can modify complicated databases, plugins, and themes. You can also utilize the plain-text interface to control menus, choices, and comments if you like.<\/p>\n\n\n\n<p>In the end, WP-CLI simplifies and accelerates a variety of challenging activities. Additionally, WP-CLI can be expanded. If you have specific requirements, you can <a href=\"https:\/\/make.wordpress.org\/cli\/handbook\/commands-cookbook\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">write unique scripts<\/a> that execute using WP-CLI according to your requirements.<\/p>\n\n\n\n<p>Before continuing, it&#8217;s crucial to understand that WP-CLI is a server-installed utility rather than a plugin for your WordPress website. In other words, for consistent access, you must install WP-CLI on both your live hosting server and your local development environment.<\/p>\n\n\n\n<h2 class=\"h3 wp-block-heading\" id=\"h-best-wp-cli-commands-to-manage-your-wordpress-site\">Best WP-CLI Commands to Manage your WordPress Site<\/h2>\n\n\n\n<p>Using the command line, you can open the folder for the WordPress website you want to control after installing WP-CLI. You&#8217;ll need <a href=\"https:\/\/help.github.com\/articles\/connecting-to-github-with-ssh\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">secure shell access<\/a> if you&#8217;re working in real-time on your hosting server.<\/p>\n\n\n\n<p>But first, we advise testing these commands in a development setting! Before utilizing this tool on a live server, you should be reasonably comfortable with it because there is no undo option. Here are four helpful ways to practice utilizing WP-CLI on your site to get you started.<\/p>\n\n\n\n<h3 class=\"h4 wp-block-heading\" id=\"h-look-into-the-the-wp-config-php-file\">Look Into the the wp-config.php File<\/h3>\n\n\n\n<p>When it comes to enabling you to configure a new site, WP-CLI has always been quite effective. For instance, you may create a new config file and include all the necessary information in it using <a href=\"https:\/\/developer.wordpress.org\/cli\/commands\/config\/create\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">the handy wp config create command<\/a>. usually completed considerably more quickly than the conventional method, especially if you have a quick typing speed.<\/p>\n\n\n\n<p>WP-CLI, however, goes a step further. The primary <code>wp config<\/code> command has two subcommands.<\/p>\n\n\n\n<p>The first one is this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp config get<\/code><\/pre>\n\n\n\n<p>This lists constants and globals as defined in your current <code>wp-config.php<\/code> file.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wp-config-file.png\" alt=\"WP Config Get WP-CLI\" class=\"wp-image-8437\" width=\"518\" height=\"373\" srcset=\"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wp-config-file.png 691w, https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wp-config-file-300x216.png 300w\" sizes=\"auto, (max-width: 518px) 100vw, 518px\" \/><\/figure>\n<\/div>\n\n\n<p>The other one is this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp config path<\/code><\/pre>\n\n\n\n<p>This command simply displays a path to the current <code>wp-config.php<\/code> file.<\/p>\n\n\n\n<p>Another WP-CLI command is available if you wish to interact with your WordPress installation even more closely:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp db size --tables<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wp-config-path.png\" alt=\"WordPress Database Size\" class=\"wp-image-8438\" width=\"515\" height=\"370\" srcset=\"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wp-config-path.png 686w, https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wp-config-path-300x216.png 300w\" sizes=\"auto, (max-width: 515px) 100vw, 515px\" \/><\/figure>\n<\/div>\n\n\n<p>Very helpful in assisting you in determining whether or not you require database improvement.<\/p>\n\n\n\n<h3 class=\"h4 wp-block-heading\" id=\"h-run-core-updates\">Run Core Updates<\/h3>\n\n\n\n<p>Running an update often entails login into your admin and visiting a few pages to update your site.<\/p>\n\n\n\n<p>With WP-CLI, updates are easily run with <a href=\"https:\/\/developer.wordpress.org\/cli\/commands\/core\/update\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">one simple command<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp core update<\/code><\/pre>\n\n\n\n<p>The ability to accept parameters to alter the behavior of the method makes it special. Consider the case where you recently updated WordPress to a version that broke a crucial plugin for your website. Although the creator of that plugin hasn&#8217;t had a chance to update it yet, your website must function properly. Although updating a site regularly is preferable, you can change the core by adding the version flag to your command and going back to a time when there was no conflict:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp core update --version=6.02<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wordpress-core-update-1024x256.png\" alt=\"WordPress Core Update\" class=\"wp-image-8440\" width=\"768\" height=\"192\" srcset=\"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wordpress-core-update-1024x256.png 1024w, https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wordpress-core-update-300x75.png 300w, https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wordpress-core-update-768x192.png 768w, https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wordpress-core-update.png 1350w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n\n\n<h3 class=\"h4 wp-block-heading\" id=\"h-update-disable-and-delete-unwanted-plugins\">Update, Disable, and Delete Unwanted Plugins<\/h3>\n\n\n\n<p>Normally, to deactivate a plugin that has fully broken your site (or even just disabled your admin), you must get in via FTP and modify the name of the plugin&#8217;s folder. On the other side, deactivating plugins may be done with a <a href=\"https:\/\/developer.wordpress.org\/cli\/commands\/plugin\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">simple WP-CLI command<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp plugin deactivate plugin-name-example<\/code><\/pre>\n\n\n\n<p>If a plugin is giving you serious trouble and needs to be deleted, you can do so using the delete command instead:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp plugin delete plugin-name-example<\/code><\/pre>\n\n\n\n<p>Additionally, you can avoid manual plugin updates by using a command that works similarly to the WordPress core update feature:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp plugin update --all<\/code><\/pre>\n\n\n\n<p>Additionally, you can check the status of the plugins that are currently installed on your website using WP-CLI, which is probably something I should have stated at the outset. For that, employ:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp plugin status<\/code><\/pre>\n\n\n\n<p>These instructions might not seem like they would save a lot of time when used alone. It&#8217;s crucial to keep in mind, nevertheless, that visiting the server directly is far quicker than waiting for a web browser to render all the scripts and styles necessary for a graphical user interface. You might be astonished by how quickly your additional time mounts up if you routinely have to do this kind of work.<\/p>\n\n\n\n<h3 class=\"h4 wp-block-heading\" id=\"h-reset-user-passwords\">Reset User Passwords<\/h3>\n\n\n\n<p>Consider a scenario where you forgot your WordPress admin password. You&#8217;ve attempted the link to reset your password, but for some reason, your mailbox isn&#8217;t receiving the reset email. Are you permanently unable to access your WordPress website? With WP-CLI, not so.<\/p>\n\n\n\n<p>With WP-CLI, quick user management is possible, and with the line below, you may <a href=\"https:\/\/developer.wordpress.org\/cli\/commands\/user\/update\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">reset passwords<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp user update adminuser@example.com --user_pass=new-password-example<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wp-cli-user-update.png\" alt=\"WP-CLI User Update\" class=\"wp-image-8441\" width=\"673\" height=\"131\" srcset=\"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wp-cli-user-update.png 897w, https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wp-cli-user-update-300x59.png 300w, https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/wp-cli-user-update-768x150.png 768w\" sizes=\"auto, (max-width: 673px) 100vw, 673px\" \/><\/figure>\n\n\n\n<p>There&#8217;s no need to freak out or fret about difficult workarounds to regain access to your site with simple commands. The days of manually hashing your password and entering it into the database are long gone.<\/p>\n\n\n\n<p>Additionally, utilizing this method does not compromise the security of your website because everything is done over a secure connection to your server.<\/p>\n\n\n\n<h3 class=\"h4 wp-block-heading\" id=\"h-backup-and-manipulate-the-database\">Backup and Manipulate the Database<\/h3>\n\n\n\n<p>Direct database interaction is difficult to achieve with WordPress. When you wish to carry out ostensibly straightforward operations, like running an update without a plugin or looking up and changing a preset phrase, this might be irritating.<\/p>\n\n\n\n<p>To make these tasks simpler, use WP-CLI. You can <a href=\"https:\/\/developer.wordpress.org\/cli\/commands\/db\/optimize\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">optimize<\/a> and <a href=\"https:\/\/developer.wordpress.org\/cli\/commands\/db\/repair\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">repair<\/a> databases with straightforward commands like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp db optimize<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>wp db repair<\/code><\/pre>\n\n\n\n<p>If you are writing a custom query, you can quickly test it out by using the <a href=\"https:\/\/developer.wordpress.org\/cli\/commands\/db\/query\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">query command<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp db query \"SELECT * FROM wp_options\"<\/code><\/pre>\n\n\n\n<p>However, it&#8217;s imperative that you understand how to establish backups before you become very trigger-happy with the database. The command to use in WP-CLI to <a href=\"https:\/\/developer.wordpress.org\/cli\/commands\/db\/export\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">create SQL backups<\/a> is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp db export<\/code><\/pre>\n\n\n\n<p>If something goes wrong, you can utilize the SQL file that is created as a backup of your site&#8217;s database. Even when used with backup plugins, it performs effectively.<\/p>\n\n\n\n<p>The name that will be provided to the file is somewhat arbitrary. Use this to assign your own:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp db export yourname.sql<\/code><\/pre>\n\n\n\n<p>Working with the database on your site is a breeze, thanks to WP-CLI.<\/p>\n\n\n\n<h3 class=\"h4 wp-block-heading\" id=\"h-clean-post-revisions\">Clean Post Revisions<\/h3>\n\n\n\n<p>The number of changes on some of our most regularly updated posts exceeds 200, which makes managing them extremely difficult.<\/p>\n\n\n\n<p>The bar at the top appears when you access WordPress&#8217; standard revision comparison page (see below screenshot). You can select the two revisions you want to compare through it. If a post has fewer than 20 revisions, this is OK. However, if there are more than 100, the bar is no longer clickable, making it difficult to quickly select the precise revision you want and necessitating pixel-perfect clicks. The bar is simply too thick.<\/p>\n\n\n\n<p>To battle this in some way, you can set a limit on the number of revisions allowed per post in your <code>wp-config.php<\/code> file (eg. <code>define('WP POST REVISIONS', 40)<\/code>;). However, this merely restricts future acts that you take. All current revisions that are higher than that threshold must be removed. There are several ways to accomplish this. One is done using a plugin. The second is through WP-CLI.<\/p>\n\n\n\n<p>And the WP-CLI way is just much quicker. To get started, you need to install an additional WP-CLI package called <a href=\"https:\/\/github.com\/trepmal\/wp-revisions-cli\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">wp-revisions-cli<\/a>.<\/p>\n\n\n\n<p>An easy command can be used to accomplish this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp package install trepmal\/wp-revisions-cli<\/code><\/pre>\n\n\n\n<p>After that, you get to use a handful of cool new WP-CLI commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp revisions clean<\/code><\/pre>\n\n\n\n<p>That eliminates all posts&#8217; previous revisions. Only the most recent changes are kept by default, which is <code>WP_POST_REVISIONS<\/code>.<\/p>\n\n\n\n<p>As an alternative, if you choose to be more involved in the revision process, you can, for example, manage the revisions for a particular post:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp revisions list --post_id=ID<\/code><\/pre>\n\n\n\n<p>This command gives you a list of all the revisions for a given post.<\/p>\n\n\n\n<p>Or:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp revisions clean --post_id=ID --before-date=DATE<\/code><\/pre>\n\n\n\n<p>which deletes edits to a specific post that was made on or before a certain date (YYYY-MM-DD).<\/p>\n\n\n\n<p>Overall, a cool function, especially if you frequently edit your existing posts, which results in numerous revisions. I&#8217;m interested to see what future updates the <code>wp-revisions-cli<\/code> package will offer.<\/p>\n\n\n\n<h3 class=\"h4 wp-block-heading\" id=\"h-create-a-child-theme\">Create a Child Theme<\/h3>\n\n\n\n<p>Making child themes is not really challenging. To make sure that some minor details haven&#8217;t been altered, you must first check the <a href=\"https:\/\/codex.wordpress.org\/Child_Themes\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">official reference at Codex<\/a>. Then, you must create a functions.php file, place CSS in a new directory, and so on and so forth.<\/p>\n\n\n\n<p>You can use a <a href=\"https:\/\/developer.wordpress.org\/cli\/commands\/scaffold\/child-theme\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">a quicker method<\/a> with WP-CLI. You simply do this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp scaffold child-theme NEW-CHILD-SLUG --parent_theme=SLUG --theme_name=TITLE<\/code><\/pre>\n\n\n\n<p>Just that. An operable, blank child theme built on a predetermined parent theme is what you receive as a consequence.<\/p>\n\n\n\n<p>A few extra parameters are also available. For example, you could try this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp scaffold child-theme SLUG --parent_theme=SLUG --theme_name=TITLE --author=FULL-NAME --author_uri=URI --theme_uri=URI --activate --force<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><code>--force<\/code> overwrites files that already exist.<\/li><\/ul>\n\n\n\n<h3 class=\"h4 wp-block-heading\" id=\"h-create-dummy-content-for-testing\">Create Dummy Content for Testing<\/h3>\n\n\n\n<p>Dummy content is something you most likely need rather frequently when working on any kind of WordPress project.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>It&#8217;s possible that you&#8217;re developing a new plugin that modifies posts after they have been processed.<\/li><li>Perhaps you want to check to make sure your pagination is flawless.<\/li><li>Perhaps you should add more items to your menus for testing.<\/li><\/ul>\n\n\n\n<p>In such situations, I used to typically press Ctrl+F and begin looking for that annoying XML dump of, for instance, WordPress material that I had lying around somewhere.<\/p>\n\n\n\n<p>Anyway, as you\u2019d imagine, WP-CLI has some options for that too:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp post generate --count=6<\/code><\/pre>\n\n\n\n<p>This command creates 6 empty posts, but you don\u2019t need to stop at just 6 \u2013 WP-CLI promises that 1000 is also a perfectly executable value.<\/p>\n\n\n\n<p>Or, to make things more factual:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl http:\/\/loripsum.net\/api\/4 | wp post generate --post_content --count=6<\/code><\/pre>\n\n\n\n<p>The command creates 6 posts, each having 4 paragraphs of dummy lorem ipsum text imported from loripsum.net.<\/p>\n\n\n\n<h3 class=\"h4 wp-block-heading\" id=\"h-blank-your-site\">Blank Your Site<\/h3>\n\n\n\n<p>One pretty cool WP-CLI command enables you to completely remove all of the content from your site, including posts, comments, terms, and meta while keeping the users and site setup untouched. This is it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp site empty<\/code><\/pre>\n\n\n\n<p>The amount of time this will save you will be immediately apparent if you frequently utilize the same development WordPress setup for your testing, experiments, etc.<\/p>\n\n\n\n<p>This WP-CLI command is incredibly quick, even if you can get the same result by manually looking through your content or using <code>phpMyAdmin<\/code>.<\/p>\n\n\n\n<p>You could also:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp site empty --uploads<\/code><\/pre>\n\n\n\n<p>The command gets rid of everything in your \u201cuploads\u201d folder as well.<\/p>\n\n\n\n<h3 class=\"h4 wp-block-heading\" id=\"h-reinstall-wordpress-core\">Reinstall WordPress Core<\/h3>\n\n\n\n<p>Using WP-CLI, you can also reinstall WordPress core. The WordPress core would be downloaded without the pre-installed themes and plugins using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp core download --skip-content --force<\/code><\/pre>\n\n\n\n<h3 class=\"h4 wp-block-heading\" id=\"h-remove-all-spam-comments\">Remove All Spam Comments<\/h3>\n\n\n\n<p>First of all, WP-CLI offers you a variety of options for managing comments. You can, for instance:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>create new comments with wp comment create;<\/li><li>update comments with wp comment update;<\/li><li>approve comments with wp comment approve;<\/li><li>and <a href=\"https:\/\/developer.wordpress.org\/cli\/commands\/comment\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">a lot more<\/a>.<\/li><\/ul>\n\n\n\n<p>However, removing all of the spam comments from your website at once can be the most intriguing thing you can do in this situation. This is very useful if you ever discover that your database has hundreds of brand-new spam comments.<\/p>\n\n\n\n<p>The command is this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp comment delete $(wp comment list --status=spam --format=ids)<\/code><\/pre>\n\n\n\n<p>What a clever hack! The ID(s) of the comment(s) that should be deleted is required as an argument for the primary wp comment delete command. Therefore, we are calling another command, wp comment list, which displays a list of all the comments that have been flagged as spam to supply the ID(s).<\/p>\n\n\n\n<h3 class=\"h4 wp-block-heading\" id=\"h-tame-wp-cron\">Tame wp-cron<\/h3>\n\n\n\n<p>The standard wp-cron mechanism hasn\u2019t been the most reliable thing. More or less, when you schedule a post in WordPress, you can never be 100% sure that it will indeed go live.<\/p>\n\n\n\n<p>WP-CLI can help you tame cron just a bit with the use of <a href=\"https:\/\/developer.wordpress.org\/cli\/commands\/cron\/event\/run\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">this command<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp cron event run --due-now<\/code><\/pre>\n\n\n\n<p>The command triggers all cron events due right now.<\/p>\n\n\n\n<h3 class=\"h4 wp-block-heading\" id=\"h-get-help-on-any-wp-cli-command\">Get Help on Any WP-CLI Command<\/h3>\n\n\n\n<p>Even though WP-CLI is fantastic, it still uses a text interface, making it challenging to constantly remember which command to execute when.<\/p>\n\n\n\n<p>There are two actions you can take to assist yourself:<\/p>\n\n\n\n<p>The standard help command is first:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp help COMMAND<\/code><\/pre>\n\n\n\n<p>This input displays help on any command in WP-CLI.<\/p>\n\n\n\n<p>Next, there\u2019s the &#8211;prompt argument that works with most WP-CLI commands. For example, if I attempt to generate some new content like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp post generate --prompt<\/code><\/pre>\n\n\n\n<p>WP-CLI will list all the arguments that are available for the generate command and let me fill in the blanks. <\/p>\n\n\n\n<h2 class=\"h3 wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p>Many chores that are sometimes regarded as tedious are simplified by WP-CLI to the point that doing them is nearly enjoyable. You may utilize WP-CLI to easily access practically everything you need on your WordPress site, saving you time from having to spend hours getting over roadblocks that are holding you back from addressing the underlying problems.<\/p>\n\n\n\n<p>The circumstances listed above are just a few of the many uses for WP-CLI; until we fully grasp its possibilities, they will only serve as a small portion of its potential value.<\/p>\n\n\n\n<p>Have you got any inquiries concerning WP-CLI? Or perhaps you&#8217;d want to share some of your own clever tricks with us. Let us know in the comments section below!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress is a fantastic project, but as with any piece of software, there may be times when you wish you had a backdoor into your code and database. You know what we&#8217;re talking about if you&#8217;ve ever attempted to reset your admin privileges using a faulty reset password link.<\/p>\n","protected":false},"author":13,"featured_media":8421,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[256],"tags":[4750,184,44,248],"class_list":["post-8435","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-command-line","tag-tips","tag-wordpress","tag-wp-cli"],"featured_image_src":"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/best_wp-cli_commands_to_help_you_manage_your_wordpress_website.png","author_info":{"display_name":"Joseph","author_link":"https:\/\/www.fastcomet.com\/blog\/author\/joseph"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Top WP-CLI v2 Commands to Manage WordPress Like a Pro | FastComet<\/title>\n<meta name=\"description\" content=\"Learn how to automate repetitive tasks with the official command-line interface for WordPress WP-CLI v2.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Top WP-CLI v2 Commands to Manage WordPress Like a Pro | FastComet\" \/>\n<meta property=\"og:description\" content=\"Learn how to automate repetitive tasks with the official command-line interface for WordPress WP-CLI v2.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli\" \/>\n<meta property=\"og:site_name\" content=\"FastComet Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-16T14:22:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-16T14:22:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/best_wp-cli_commands_to_help_you_manage_your_wordpress_website.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Joseph\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Joseph\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Top WP-CLI v2 Commands to Manage WordPress Like a Pro | FastComet","description":"Learn how to automate repetitive tasks with the official command-line interface for WordPress WP-CLI v2.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli","og_locale":"en_US","og_type":"article","og_title":"Top WP-CLI v2 Commands to Manage WordPress Like a Pro | FastComet","og_description":"Learn how to automate repetitive tasks with the official command-line interface for WordPress WP-CLI v2.","og_url":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli","og_site_name":"FastComet Blog","article_published_time":"2022-09-16T14:22:19+00:00","article_modified_time":"2022-09-16T14:22:20+00:00","og_image":[{"width":1024,"height":620,"url":"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/best_wp-cli_commands_to_help_you_manage_your_wordpress_website.png","type":"image\/png"}],"author":"Joseph","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Joseph","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli#article","isPartOf":{"@id":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli"},"author":{"name":"Joseph","@id":"https:\/\/www.fastcomet.com\/blog\/#\/schema\/person\/4f2c9600f49c872b8d56996ee3b95035"},"headline":"10+ WP-CLI Tricks to Manage Your WordPress Site","datePublished":"2022-09-16T14:22:19+00:00","dateModified":"2022-09-16T14:22:20+00:00","mainEntityOfPage":{"@id":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli"},"wordCount":2442,"commentCount":0,"image":{"@id":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli#primaryimage"},"thumbnailUrl":"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/best_wp-cli_commands_to_help_you_manage_your_wordpress_website.png","keywords":["command-line","tips","wordpress","wp-cli"],"articleSection":["WordPress"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli","url":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli","name":"Top WP-CLI v2 Commands to Manage WordPress Like a Pro | FastComet","isPartOf":{"@id":"https:\/\/www.fastcomet.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli#primaryimage"},"image":{"@id":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli#primaryimage"},"thumbnailUrl":"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/best_wp-cli_commands_to_help_you_manage_your_wordpress_website.png","datePublished":"2022-09-16T14:22:19+00:00","dateModified":"2022-09-16T14:22:20+00:00","author":{"@id":"https:\/\/www.fastcomet.com\/blog\/#\/schema\/person\/4f2c9600f49c872b8d56996ee3b95035"},"description":"Learn how to automate repetitive tasks with the official command-line interface for WordPress WP-CLI v2.","breadcrumb":{"@id":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli#primaryimage","url":"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/best_wp-cli_commands_to_help_you_manage_your_wordpress_website.png","contentUrl":"https:\/\/www.fastcomet.com\/blog\/wp-content\/uploads\/2022\/09\/best_wp-cli_commands_to_help_you_manage_your_wordpress_website.png","width":1024,"height":620,"caption":"Best WP-CLI Commands to Help You Manage Your WordPress Website"},{"@type":"BreadcrumbList","@id":"https:\/\/www.fastcomet.com\/blog\/wordpress-management-with-wp-cli#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.fastcomet.com\/blog"},{"@type":"ListItem","position":2,"name":"10+ WP-CLI Tricks to Manage Your WordPress Site"}]},{"@type":"WebSite","@id":"https:\/\/www.fastcomet.com\/blog\/#website","url":"https:\/\/www.fastcomet.com\/blog\/","name":"FastComet Blog","description":"FastComet Web Hosting Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.fastcomet.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.fastcomet.com\/blog\/#\/schema\/person\/4f2c9600f49c872b8d56996ee3b95035","name":"Joseph","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.fastcomet.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1aa84dc2a6398ed73c957bd1de58806d12d44e2956744ed1ae9b435d57822ab7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1aa84dc2a6398ed73c957bd1de58806d12d44e2956744ed1ae9b435d57822ab7?s=96&d=mm&r=g","caption":"Joseph"},"description":"Joseph is part of the FastComet Marketing team. With years of content writing experience behind him, it's one of his favorite activities. Joseph takes part in the SEO of the FastComet website and blog. His goal is to write comprehensive posts and guides, always aiming to help our clients with essential information. Joseph also has a thirst for knowledge and improvement, which makes the hosting environment a perfect place for him.","sameAs":["https:\/\/www.fastcomet.com\/"],"url":"https:\/\/www.fastcomet.com\/blog\/author\/joseph"}]}},"_links":{"self":[{"href":"https:\/\/www.fastcomet.com\/blog\/wp-json\/wp\/v2\/posts\/8435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fastcomet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fastcomet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fastcomet.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fastcomet.com\/blog\/wp-json\/wp\/v2\/comments?post=8435"}],"version-history":[{"count":6,"href":"https:\/\/www.fastcomet.com\/blog\/wp-json\/wp\/v2\/posts\/8435\/revisions"}],"predecessor-version":[{"id":8446,"href":"https:\/\/www.fastcomet.com\/blog\/wp-json\/wp\/v2\/posts\/8435\/revisions\/8446"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fastcomet.com\/blog\/wp-json\/wp\/v2\/media\/8421"}],"wp:attachment":[{"href":"https:\/\/www.fastcomet.com\/blog\/wp-json\/wp\/v2\/media?parent=8435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fastcomet.com\/blog\/wp-json\/wp\/v2\/categories?post=8435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fastcomet.com\/blog\/wp-json\/wp\/v2\/tags?post=8435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}