PHPackages                             marspress/post-type - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. marspress/post-type

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

marspress/post-type
===================

Utility package to initiate new post types in WordPress.

1.0(4y ago)03GPL-2.0PHPPHP &gt;=7.4

Since Dec 8Pushed 4y ago2 watchersCompare

[ Source](https://github.com/MARSWorksInc/wordpress-post-types)[ Packagist](https://packagist.org/packages/marspress/post-type)[ RSS](/packages/marspress-post-type/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

MarsPress PostType
==================

[](#marspress-posttype)

### Installation

[](#installation)

Require the composer package in your composer.json with `marspress/post-type` with minimum `dev-main` OR run `composer require marspress/post-type`

### Resource

[](#resource)

- [https://developer.wordpress.org/reference/functions/register\_post\_type/](https://developer.wordpress.org/reference/functions/register_post_type/)

### Usage

[](#usage)

#### Creating a New Post Type

[](#creating-a-new-post-type)

`$myPostType = new \MarsPress\PostType\Type();`

The Type class takes 13 parameters, 4 required and 9 optional.

- Key (required)(string)
    - The unique identifier for the post type.
    - This should only contain lower case characters, hyphens, and underscores.
    - IMPORTANT: the key should not exceed 20 characters in length. Post Type keys in WordPress can only be up to 20 characters long.
- Single Label (required)(string)
    - The single label for your Post Type.
    - This displays in admin menus and areas.
- Plural Label (required)(string)
    - The single label for your Post Type.
    - This displays in admin menus and areas.
- Supports (required)(array)
    - An array of WordPress features that the Post Type supports.
    - Resource: [https://developer.wordpress.org/reference/functions/register\_post\_type/#supports](https://developer.wordpress.org/reference/functions/register_post_type/#supports)
    - Generally, the simplest post types support `title`, `editor`, `thumbnail`. Although if your post type only is making use of custom fields, you may not need `editor`
- Slug (optional)(string)
    - The slug for the custom post type.
    - Defaults to the `key`.
    - This should be given without leading and proceeding slashes. E.g. `test/sample` would result in your posts permalinks being `/test/sample/`
- Icon (optional)(string)
    - The dashicon to use for the Post Type.
    - Defaults to `dashicons-admin-post`
    - Resource:
- Menu Position (optional)(int)
    - Position in the admin menu.
    - Defaults to `30`.
    - Resource: [https://developer.wordpress.org/reference/functions/register\_post\_type/#menu\_position](https://developer.wordpress.org/reference/functions/register_post_type/#menu_position)
- Has Archive (optional)(bool)
    - Whether the Post Type should have an archive route generated for it or not.
    - Defaults to `true`.
    - E.g. if true, an archive route will be generated based on your post type slug, the archive route will be `/test/sample/`
- Public (optional)(bool)
    - If the Post Type should be visible to the public.
    - Defaults to `true`.
    - Generally should always stay true unless if you are using the post type strictly for admin usages.
- Show In Rest (optional)(bool)
    - If the Post Type should be available to the REST API.
    - Defaults to `true`.
    - IMPORTANT: because Gutenberg uses the REST API, this should be `true` if you have to use the `editor` support.
- Override (optional)(bool)
    - If your Post Type should override existing post types.
    - Defaults to `false`.
    - This is useful if you need to modify any of the Core WordPress post types, or post types from other plugins.
- Translate Interface (optional)(bool)
    - Whether the post type labels should be translated in the admin interface.
    - Defaults to `true`.
    - Useful if you have a multi-language site but want the admin are to remain in English.
- Text Domain (optional)(string)
    - The text domain used for the translation interface.
    - Defaults to the `key`.
    - This is only used if Translate Interface is set to `true`.

#### Registering Custom Rewrite Rules

[](#registering-custom-rewrite-rules)

You must already have initiated a new class with `$myPostType = new \MarsPress\PostType\Type();`

You can then call the `add_rewrite_rule` method with `$myPostType->add_rewrite_rule();`

IMPORTANT: after registering new rewrite rules, it is required to flush the rule cache. This can be done in WordPress admin by going to Settings &gt; Permalinks and clicking the "Save Changes" button (you do not actually have to make any changes).

The `add_rewrite_rule` method takes 3 parameters, 2 required and 1 optional.

- Rule (required)(string)
    - This should be your regex rule such as `test/samples/(.*)/(.*)?$`
- Match (required)(string)
    - This should be your matching URL query. It is important to not double quote the `$matches[]` as that will result in PHP warnings and the rewrite rule failing.
    - E.g. `index.php?post_type=sample&sample=$matches[2]&sample_category=$matches[1]`
    - All the front-end WordPress matches will start with `index.php`.
- After (optional)(string)
    - This sets the priority of the rewrite rule in the stack of WordPress rewrite rules.
    - Defaults to `top`.
    - Valid values are `top` or `bottom`.

#### Available Methods

[](#available-methods)

You must already have initiated a new class with `$myPostType = new \MarsPress\PostType\Type();`

- `$myPostType->get_key();`
    - This will return the key of the post type.
    - This is useful for WordPress conditions such as `if( is_singular( $myPostType->get_key() ) ){}`
- `$myPostType->get_object();`
    - This will return the WP\_Post\_Type object.
    - Resource: [https://developer.wordpress.org/reference/classes/wp\_post\_type/](https://developer.wordpress.org/reference/classes/wp_post_type/)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1620d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/adcbfb731b685a8b219008c6c3673b843a0c9aa66c4b6d2a2c1ab03eef959f08?d=identicon)[martian-jesse](/maintainers/martian-jesse)

---

Top Contributors

[![martian-jesse](https://avatars.githubusercontent.com/u/86261906?v=4)](https://github.com/martian-jesse "martian-jesse (4 commits)")

### Embed Badge

![Health badge](/badges/marspress-post-type/health.svg)

```
[![Health](https://phpackages.com/badges/marspress-post-type/health.svg)](https://phpackages.com/packages/marspress-post-type)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
