In This Tutorial:
WP-CLI allows you to manage your WordPress website(s) from the command line. It’s even simple to gather important details about your existing content, like posts/pages for example. These details are needed in the syntax of commands to manipulate the various components of your website. In this guide, you will learn how to list details of your Posts and Pages using WP-CLI.
List Post Details
Posts can be easily found, using the wp post list sub-command. The instructions below, will guide you through the process of listing the details of your Posts, using WP-CLI.
SSH into your server as the cPanel user that owns the website you would like to work with.
Use the cd command to switch to the document root directory of your website.
Example: cd public_html/wp
NOTE: Be sure to replace public_html/wp with the actual path to the document root directory of your website.Run the following command:
wp post list
The output will be similar to the example below:
[email protected] [~/public_html/wp]# wp post list +----+----------------+------------------+---------------------+-------------+ | ID | post_title | post_name | post_date | post_status | +----+----------------+------------------+---------------------+-------------+ | 39 | Blogging 101 | blogging-101 | 2018-02-21 16:17:58 | publish | | 40 | Basic...nomies | basic-taxonomies | 2018-02-21 16:17:58 | publish | | 41 | Tips...Writing | tip...er-writing | 2018-02-21 16:17:58 | publish | +----+----------------+------------------+---------------------+-------------+
List Page Details
Since Pages are stored in the same manner as Posts, you can use the wp post list sub-command to find details about the Pages for your website. The instructions below will guide you through the process of displaying details for your Pages using WP-CLI.
SSH into your server as the cPanel user that owns the website you would like to work with.
Use the cd command to switch to the document root directory of your website.
Example: cd public_html/wp
NOTE: Be sure to replace public_html/wp with the actual path to the document root directory of your website.Run the following command:
wp post list –post_type=page
The output should be similar to the example below:
[email protected] [~/public_html/wp]# wp post list --post_type=page +----+-----------------+-----------------+---------------------+-------------+ | ID | post_title | post_name | post_date | post_status | +----+-----------------+-----------------+---------------------+-------------+ | 42 | About Us | about-us | 2018-02-21 16:17:58 | publish | | 44 | Clients | clients | 2018-02-21 16:17:58 | publish | | 46 | Gallery | gallery | 2018-02-21 16:17:58 | publish | | 48 | Resume | resume | 2018-02-21 16:17:58 | publish | | 50 | Info | info | 2018-02-21 16:17:58 | publish | | 52 | Testimonials | testimonials | 2018-02-21 16:17:58 | publish | | 54 | Contact Us | contact-us | 2018-02-21 16:17:58 | publish | | 37 | Home | home | 2018-02-21 16:17:57 | publish | +----+-----------------+-----------------+---------------------+-------------+
Now that you are familiar with how to locate the details of Pages and Posts, you will be able to specify the details needed in the syntax of WP-CLI commands.
Learn more about WP-CLI, the command-line interface for WordPress, and how to streamline your WordPress maintenance workflows!