Can I create multiple pages at once using WP-CLI?

There are a few ways. As mentioned, post generate.

wp post generate --count=10 --post_type=page --post_date=1999-01-04
curl http://loripsum.net/api/5 | wp post generate --post_content --count=10

You could write your own custom command. See the List of community commands for examples or the package index.

<?php
/**
 * Implements example command.
 */
class Example_Command extends WP_CLI_Command {

    /**
     * Prints a greeting.
     * 
     * ## OPTIONS
     * 
     * <name>
     * : The name of the person to greet.
     * 
     * ## EXAMPLES
     * 
     *     wp example hello Newman
     *
     * @synopsis <name>
     */
    function hello( $args, $assoc_args ) {
        list( $name ) = $args;

        // Print a success message
        WP_CLI::success( "Hello, $name!" );
    }
}

WP_CLI::add_command( 'example', 'Example_Command' );

And WPTest.io is a good example of using the import command to create test content from xml.

#!/bin/sh
#
# WP Test - WP-CLI Quick Install Script
# http://wptest.io/
#
# Note: This script assumes you have wp-cli installed.
#####################################################################################

# Ask user where WordPress is installed.
printf "Please provide the local path to your WordPress install: "
read WPPATH

# Import WP Test data.
cd $WPPATH
curl -OL https://raw.githubusercontent.com/manovotny/wptest/master/wptest.xml
wp import wptest.xml --authors=create
rm wptest.xml

Leave a Comment