Date: 11/8/19 2 Minutes To Read
WP-CLI is a command line tool that comes with your WordPress Hosting package. You can use it to manage your WordPress site with quick and intuitive command line instructions. Utilized properly, WP-CLI can drastically speed up your workflow and replace tedious dashboard operations with efficient scripts you can repeat and automate.
Using the new Gutenberg editor lets you place content into convenient blocks. But what happens if you need to copy the content of a long int HTML? You would need to preview each Gutenberg block separately as HTML, copy, and paste it into a local HTML file. For a long post, this is incredibly time-consuming and will introduce multiple opportunities for error. Using WP-CLI can ensure you copy the HTML content perfectly and preserve it in an HTML file.
WP-CLI provides an easy shortcut for accessing specific database tables where your content. Using the command below you can have WP-CLI go into the database, get post content, and output that content to a file:
Send content to a file in the same directory:
$ wp post get 123 --field=content > file.html
Second content to a file in your home directory by adding a tilde
$ wp post get 123 --field=content > ~/file.html
Here are the steps on how to use the above commands and where they need to go:
- Log into your terminal
- Navigate to the WordPress site directory (where the core files reside)
- Get your post ID using WP-CLI or previewing a URL from the post list in the dashboard (URL will contain
- Use one of the above code snippets with the post ID number
When you visit your file, you will notice that it is filled with HTML content you can save or paste into WordPress as needed.
Learn more about WP-CLI, the command-line interface for WordPress, and how to streamline your WordPress maintenance workflows!