PHP code example of motivast / wp-cli-seed-command

1. Go to this page and download the library: Download motivast/wp-cli-seed-command library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

motivast / wp-cli-seed-command example snippets




use Motivast\WP_CLI\Seed\AbstractSeeder;

class Seeder extends AbstractSeeder
{
	/**
	 * Run the database seeds.
	 *
	 * @return void
	 */
	public function run()
	{
		//
	}
}



use Motivast\WP_CLI\Seed\AbstractSeeder;

class Seeder extends AbstractSeeder
{
	/**
	 * Run the database seeds.
	 *
	 * @return void
	 */
	public function run()
	{
		update_option('blogname', 'WP CLI Seed Command');
		update_option('blogdescription', '');

		$defaults = [
			'post_type' => 'page',
			'post_status' => 'publish',
		];

		$home_id = wp_insert_post( wp_parse_args( [
			'post_title' => 'Home'
		], $defaults ) );

		$about_id = wp_insert_post( wp_parse_args( [
			'post_title' => 'About'
		], $defaults ) );

		$contact_id = wp_insert_post( wp_parse_args( [
			'post_title' => 'Contact'
		], $defaults ) );

 		// Update homepage
		update_option( 'show_on_front', 'page' );
		update_option( 'page_on_front', $home_id );
	}
}



use Motivast\WP_CLI\Seed\AbstractSeeder;

class Options extends AbstractSeeder
{
	/**
	 * Run the database seeds.
	 *
	 * @return void
	 */
	public function run()
	{
		update_option('blogname', 'WP CLI Seed Command');
		update_option('blogdescription', '');
	}
}



use Motivast\WP_CLI\Seed\AbstractSeeder;

class Pages extends AbstractSeeder
{
	/**
	 * Run the database seeds.
	 *
	 * @return void
	 */
	public function run()
	{
		$defaults = [
			'post_type' => 'page',
			'post_status' => 'publish',
		];

		$home_id = wp_insert_post( wp_parse_args( [
			'post_title' => 'Home'
		], $defaults ) );

		$about_id = wp_insert_post( wp_parse_args( [
			'post_title' => 'About'
		], $defaults ) );

		$contact_id = wp_insert_post( wp_parse_args( [
			'post_title' => 'Contact'
		], $defaults ) );

 		// Update homepage
		update_option( 'show_on_front', 'page' );
		update_option( 'page_on_front', $home_id );
	}
}



use Motivast\WP_CLI\Seed\AbstractSeeder;

er extends AbstractSeeder
{
	/**
	 * Run the database seeds.
	 *
	 * @return void
	 */
	public function run()
	{
		$this->call(Options::class);
		$this->call(Pages::class);
	}
}