# 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.

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

```php
// Instantiate the Books PostType class.
$books = new Books;

// Register the books PostType to WordPress.
$books->register();
```

{% hint style="info" %}
The `register()` method hooks into WordPress and sets all the actions and filters required to create your custom post type. You do not need to add any of your PostTypes code in actions/filters. Doing so may lead to unexpected results.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://posttypes.jjgrainger.co.uk/post-types/create-a-post-type.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
