1

I am new to WP-CLI and having trouble finding examples of what I want to do. I know how to create a single page. wp post create --post_type=page --post_status=publish --post_title='Contact'

Is there a way to create multiple pages with a single command?

2

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
1

After looking further I found a page on the site. It looks like you can.

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

http://wp-cli.org/commands/post/generate/

1

You could just chain them up using the && operator. E.g:

wp post create --post_type=page --post_status=publish --post_title='Contact' && wp post create --post_type=page --post_status=publish --post_title='Home' && wp post create --post_type=page --post_status=publish --post_title='Another Page' ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.