codesvault/wp-seeder

Database seeder for WordPress

1.1.0 2023-06-16 21:01 UTC

This package is auto-updated.

Last update: 2024-05-16 23:06:25 UTC


README

Add demo data in the Database from terminal.

Installation

It is required to install it using composer composer install codesvault/wp-seeder.
It supports PHP >= 7.1




Uses

To create a new seeder, run ./vendor/bin/wpseed new and provide necessary inputs.
It will generate /seeders directory in /database directory. Don't move this directory to other location, it must be here. In the /database/seeders folder you will have your seeder which was automatically generated, the file name will be same as the class name that you had given input.


Now change the $table property according to your table name where you want to store data. $row property is for number of rows you want to generate in the table. For generating demo data WP Seeder has build-in support of FakerPHP.

class yourClassName extends WPSeeder
{
    public $table = "cv_users";    // db table name without prefix, default is posts.
    public $row = 5000;      // number of db table row will create, default is 1.

    public function run()
    {
        // add data that need to be inserted in database.
        // array key is the column name, value is data that will be stored.
        return array(
            'name' => $this->faker()->unique()->name(),
            'email' => $this->faker()->unique()->email(),
            'password' => $this->faker()->unique()->password()
        );
    }
}

If you want to create more seeders for different tables then just repeate the above process.
Now just run ./vendor/bin/wpseed store in the terminal and data will be stored in the database.


.