concept-image/wp-custom-post-types
Composer 安装命令:
composer require concept-image/wp-custom-post-types
包简介
Register custom post types and taxonomies in WordPress.
README 文档
README
Requirements
- PHP >= 8.0
- WordPress >= 6.7
- Roots Bedrock >= 1.26
- Roots Acorn >= 4.3
Installation
You can install this package with Composer:
composer require concept-image/wp-custom-post-types
Usage
This package provides a convenient way to create and manage custom post types and taxonomies in WordPress using a structured approach. It leverages the power of Roots Bedrock and Acorn to integrate seamlessly into your WordPress project.
Custom Post Types
To create a custom post type, you need to define a class in the app/CustomPostTypes directory. The class should extend PostType and have a protected static $name property and a getArgs method that returns the arguments for the custom post type registration.
Example:
namespace App\CustomPostTypes;
use ConceptImage\WpCustomPostTypes\PostType;
class Book extends PostType
{
protected static string $name = 'book';
public function getArgs(): array
{
return [
'label' => 'Books',
'public' => true,
'supports' => ['title', 'editor', 'thumbnail'],
'taxonomies' => ['genre'],
];
}
}
Custom Taxonomies
To create a custom taxonomy, you need to define a class in the app/Taxonomies directory. The class should extend Taxonomy and have a protected static $name property, an $object_type property, and a getArgs method.
Example:
namespace App\Taxonomies;
use ConceptImage\WpCustomPostTypes\Taxonomy;
class Genre extends Taxonomy
{
protected static string $name = 'genre';
public array $object_type = ['book'];
public function getArgs(): array
{
return [
'label' => 'Genres',
'public' => true,
'hierarchical' => true,
];
}
}
Removing Base Slug from URLs
If you want to remove the base slug from your custom post type URLs (e.g., /book/my-book becomes /my-book), you can use the RemoveBaseSlug attribute on your custom post type class:
use ConceptImage\WpCustomPostTypes\Attributes\RemoveBaseSlug;
#[RemoveBaseSlug]
class Book
{
...
}
Taxonomies
To create a custom taxonomy, you need to define a class in the app/Taxonomies directory. The class should have a name property, an object_type property, and a getArgs method that returns the arguments for the taxonomy registration.
Example:
namespace App\Taxonomies;
class Genre
{
public $name = 'genre';
public $object_type = ['book'];
public function getArgs(): array
{
return [
'label' => 'Genres',
'public' => true,
'hierarchical' => true,
];
}
}
Registering Custom Post Types and Taxonomies
The package automatically registers custom post types and taxonomies defined in the app/CustomPostTypes and app/Taxonomies directories, respectively. You don't need to manually register them in your theme or plugin.
Migrate from V2 to V3
Run following command :
wp acorn custom-post-types:migration
Changelog
Please refer to CHANGELOG for more information.
Contributing
Please refer to CONTRIBUTING for more information.
License
Please refer to LICENSE for more information.
concept-image/wp-custom-post-types 适用场景与选型建议
concept-image/wp-custom-post-types 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.91k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 concept-image/wp-custom-post-types 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 concept-image/wp-custom-post-types 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.91k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-19