concept-image / wp-custom-post-types
Register custom post types and taxonomies in WordPress.
Installs: 901
Dependents: 1
Suggesters: 1
Security: 0
Stars: 0
Forks: 0
Type:package
pkg:composer/concept-image/wp-custom-post-types
- dev-main
- 3.1.0
- 3.0.26
- 3.0.25
- 3.0.24
- 3.0.23
- 3.0.22
- 3.0.21
- 3.0.20
- 3.0.19
- 3.0.18
- 3.0.17
- 3.0.16
- 3.0.15
- 3.0.14
- 3.0.13
- 3.0.12
- 3.0.11
- 3.0.10
- 3.0.9
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3
- 1.2
- 1.1
- 1.0
This package is auto-updated.
Last update: 2025-11-07 14:04:30 UTC
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.