wpfor/wp-db-seeder 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wpfor/wp-db-seeder

Composer 安装命令:

composer require wpfor/wp-db-seeder

包简介

WordPress CLI commands for database management

README 文档

README

A WordPress CLI package that provides convenient commands for seeding and managing test data in your WordPress database.

Description

WP DB Seeder allows developers to quickly populate their WordPress installations with dummy data for posts, terms, and other content types. It's perfect for development, testing, and demo environments where you need realistic data without the hassle of manual content creation.

Installation

Using Composer

composer require wpfor/wp-db-seeder

Manual Installation

  1. Download or clone this repository
  2. Place it in your WordPress plugins or mu-plugins directory
  3. Require the main file in your WordPress installation

Requirements

  • WordPress 5.0+
  • PHP 7.4+
  • WP-CLI

Commands

Seed Posts

wp db:seed posts --post_type=<post_type> --count=<number>

Options:

  • --post_type: (Required) The post type to seed (must exist)
  • --count: (Optional) Number of posts to generate (default: 10)

Examples:

wp db:seed posts --post_type=post --count=20
wp db:seed posts --post_type=page --count=5

This command generates posts with random titles, content, and excerpts using Faker, and marks them with a special meta key for future management.

Seed Terms

wp db:seed terms --taxonomy=<taxonomy> --count=<number>

Options:

  • --taxonomy: (Required) The taxonomy to seed (must exist)
  • --count: (Optional) Number of terms to generate (default: 5)

Examples:

wp db:seed terms --taxonomy=category --count=8
wp db:seed terms --taxonomy=post_tag --count=15

This command creates terms with random names and descriptions, and marks them with a special meta key for future management.

Link Terms to Posts

wp db:link terms_to_posts --post_type=<post_type> --taxonomy=<taxonomy>

Options:

  • --post_type: (Required) The post type of the posts to link (must exist)
  • --taxonomy: (Required) The taxonomy of the terms to link (must exist)

Examples:

wp db:link terms_to_posts --post_type=post --taxonomy=category
wp db:link terms_to_posts --post_type=product --taxonomy=product_cat

This command assigns random terms from the specified taxonomy to posts of the specified post type, creating realistic relationships between your seeded content.

Delete Seeded Posts

wp db:delete posts --post_type=<post_type>

Options:

  • --post_type: (Required) The post type to delete from (must exist)

Examples:

wp db:delete posts --post_type=post
wp db:delete posts --post_type=page

This command deletes only the posts that were created using the db:seed posts command, leaving your real content untouched.

Delete Seeded Terms

wp db:delete terms --taxonomy=<taxonomy>

Options:

  • --taxonomy: (Required) The taxonomy to delete from (must exist)

Examples:

wp db:delete terms --taxonomy=category
wp db:delete terms --taxonomy=post_tag

This command deletes only the terms that were created using the db:seed terms command, preserving your real taxonomy terms.

How It Works

The plugin adds metadata to each seeded post or term, allowing it to identify and manage them separately from your real content. This approach ensures that:

  1. You can easily delete just the seeded content
  2. Your real content remains untouched
  3. You can run the commands multiple times without conflicts

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-27