Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/codesvault/wp-seeder

Database seeder for WordPress
https://github.com/codesvault/wp-seeder

database mysql mysql-database seeder seeders wordpress wordpress-php-library

Last synced: 3 months ago
JSON representation

Database seeder for WordPress

Awesome Lists containing this project

README

        

# WP Seeder
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](https://fakerphp.github.io/).

```php
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.



.