Create a Post Type
Post types can be made by creating a new class that extends the PostType abstract class. All PostType classes require you to implement the name() method. Below is an example of a simple Books PostType class to get started.
use PostTypes\PostType;
class Books extends PostType
{
/**
* Returns the post type name to register to WordPress.
*
* @return string
*/
public function name(): string
{
return 'book';
}
}Register PostType to WordPress
Once your PostType class is created it can be registered to WordPress by instantiating the class and calling the register() method in your plugin or theme.
// Instantiate the Books PostType class.
$books = new Books;
// Register the books PostType to WordPress.
$books->register();Last updated