Generate: WP-CLI

Videos are not designed to be a substitute for instructions. Please refer to the detailed Documentation below.

Overview

If your web host has WP-CLI installed, you can run the following commands at the command line to generate Pages:

Looking for the Group ID?  It can be found in the Content Groups or Term Groups table, or by using the List Content Groups or List Term Groups CLI commands.

Test Generate Content

Runs the Test command, behaving as if you click the Test button for the given group_id.

wp page-generator-pro-test-content group_id

Generate Content

Runs the Generate command, behaving as if you click the Generate button for the given group_id.

wp page-generator-pro-generate-content group_id --number_of_posts= --resume_index=

Parameter Description
group_id The ID(s) of the group(s) to generate content from:
123: Runs the Generate command on Group ID 123
123,456: Runs the Generate comand on Group IDs 123 and 456
--number_of_posts= Optional; the Number of Posts to generate.  Overrides the Group’s No. Posts setting.
--number_of_posts=10: Generates 10 Posts
--resume_index= Optional; the Resume Index to use.  Overrides the Group’s Resume Index setting, which is a zero based index.
--resume_index=10: Start generating from the 9th Post (zero being the 1st Post).

Trash Generated Content

The exclude_post_ids parameter is available in Page Generator Pro 3.6.5, releasing Thursday 28th April 2022 23:59 UTC.

Runs the Trash Generated Content command, behaving as if you click the Trash Generated Content button for the given group_id.

wp page-generator-pro-trash-generated-content group_id --exclude_post_ids=

Parameter Description
group_id The ID of the group to trash generated content from:
123: Runs the trash command on Group ID 123
--exclude_post_ids= Optional; A comma separated list of Post IDs to exclude from deletion.
--exclude_post_ids=1234: Would delete all Posts generated by the specified Group ID, but would not delete generated Post ID 1234.
Want to retain specific Pages generated by the Group, and trash the rest? You’ll need to manually delete the Pages’ _page_generator_pro_group meta key first for the Pages you wish to keep – either through WordPress or the database’s post_meta table.  This will preserve those pages, and they will not be trashed when this command is subsequently run.

Delete Generated Content

The exclude_post_ids parameter is available in Page Generator Pro 3.6.5, releasing Thursday 28th April 2022 23:59 UTC.

Runs the Delete Generated Content command, behaving as if you click the Delete Generated Content button for the given group_id.

wp page-generator-pro-delete-generated-content group_id --exclude_post_ids=

Parameter Description
group_id The ID of the group to delete generated content from:
123: Runs the delete command on Group ID 123
--exclude_post_ids= Optional; A comma separated list of Post IDs to exclude from deletion.
--exclude_post_ids=1234: Would delete all Posts generated by the specified Group ID, but would not delete generated Post ID 1234.
Want to retain specific Pages generated by the Group, and delete the rest? You’ll need to manually delete the Pages’ _page_generator_pro_group meta key first for the Pages you wish to keep – either through WordPress or the database’s post_meta table.  This will preserve those pages, and they will not be deleted when this command is subsequently run.

List Content Groups

Runs the List Content Groups command, displaying information similar to that available at Page Generator Pro > Generate Content.

wp page-generator-pro-list-content-groups

Page Generator Pro: WP-CLI: List Content Groups

Test Generate Terms

Runs the Test command, behaving as if you click the Test button for the given group_id.

wp page-generator-pro-test-terms group_id

Generate Terms

Runs the Generate command, behaving as if you click the Generate button for the given group_id.

wp page-generator-pro-generate-terms group_id --number_of_terms= --resume_index=

Parameter Description
group_id The ID(s) of the group(s) to generate content from:
123: Runs the Generate command on Group ID 123
123,456: Runs the Generate command on Group IDs 123 and 456
--number_of_terms= Optional; the Number of Terms to generate.  Overrides the Group’s No. Posts setting.
--number_of_terms=10: Generates 10 Terms
--resume_index= Optional; the Resume Index to use.  Overrides the Group’s Resume Index setting.
--resume_index=10: Start generating from the 10th Term

Delete Generated Terms

The exclude_post_ids parameter is available in Page Generator Pro 3.6.5, releasing Thursday 28th April 2022 23:59 UTC.

Runs the Delete Generated Terms command, behaving as if you click the Delete Generated Terms button for the given group_id.

wp page-generator-pro-delete-generated-terms group_id --exclude_post_ids=

Parameter Description
group_id The ID of the group to delete generated terms from:
123: Runs the delete command on Group ID 123
--exclude_post_ids= Optional; A comma separated list of Term IDs to exclude from deletion.
--exclude_post_ids=1234: Would delete all Terms generated by the specified Group ID, but would not delete generated Term ID 1234.
Want to retain specific Terms generated by the Group, and delete the rest? You’ll need to manually delete the Pages’ _page_generator_pro_group meta key first for the Terms you wish to keep – either through WordPress or the database’s term_meta table.  This will preserve those terms, and they will not be deleted when this command is subsequently run.

List Term Groups

Runs the List Term Groups command, displaying information similar to that available at Page Generator Pro > Generate Terms.

wp page-generator-pro-list-term-groups

Page Generator Pro: WP-CLI: List Term Groups

Cancelling Generation

It’s recommended to cancel generation through the WordPress Administration interface’s Content or Term Groups, using the Cancel option:
Page Generator Pro: Generate: Run: Cancel CRON

Whilst it is possible to terminate any WP-CLI process using Ctrl+C, you will still need to perform the above step to notify the Plugin that the task has been cancelled.

Understanding the Result Log

Refer to the Log Documentation to understand each Result message and what it means.

Page Generator Pro: Generate via CLI: Log

Scheduling the WP-CLI Task

For users who have access to their server’s CRON jobs, you can schedule any of the above WP-CLI commands to run.

Via Crontab

Example configuration:

0 0 * * * /usr/local/bin/wp page-generator-pro-generate-content 1234 --path="/path/to/wordpress/root/" >> /path/to/wordpress/root/wp-content/page-generator-pro-cli.log 2>&1

Where:

  • 0 0 * * *: The time to run the command.  See https://crontab.guru/ to understand this format.
  • /usr/local/bin/wp: The path to the WP-CLI executable.  This path is valid if all of https://make.wordpress.org/cli/handbook/installing/ is followed.  Some hosts may have a different location for this.
  • page-generator-pro-generate 1234: The command that you want to run, with arguments.
  • /path/to/wordpress/root/: The path to the root of your WordPress installation.

A log file should be created at http://yoursite.com/wp-content/page-generator-pro-cli.log, showing the output of the command.

Via cPanel / Hosting Control Panel

Please work with your web host to ensure:

  • WP-CLI is installed,
  • A cron job is setup to call e.g. /usr/local/bin/wp page-generator-pro-generate-content 1234 --path="/path/to/wordpress/root/"

Running the WP-CLI Task Asynchronously

As SSH requires an active connection between client and server window to keep any task running (not just WP-CLI), the task will stop if you close an SSH window.

You may wish to use a solution such as tmux, which will allow the window’s command to continue running.  This also supports multiple windows, ensuring you may run multiple generation routines asynchronously.