PHPackages                             vietfreshair/cpt - 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. vietfreshair/cpt

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

vietfreshair/cpt
================

Custom post type module

1.2.2(9y ago)011MITPHP

Since Dec 23Pushed 9y ago1 watchersCompare

[ Source](https://github.com/viet-freshair/cpt)[ Packagist](https://packagist.org/packages/vietfreshair/cpt)[ RSS](/packages/vietfreshair-cpt/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

CPT
===

[](#cpt)

CPT Module

This module helps register a custom post type simpler.

Installation
============

[](#installation)

```
composer require vietartisans/cpter

```

Arguments
=========

[](#arguments)

NameTypeRequiredDescriptionDefaultnamestringyesPost type. (max. 20 characters, cannot contain capital letters or spaces)book, music,...singularstringnoname for one object of this post type. Default is Post/PageBook, Music,...pluralstringnoname for multiple object of this post type. Default is Posts/PagesPosts, Pages,...[args](#Args)arraynoAn array of arguments---[Register Post Type Arguments](https://codex.wordpress.org/Function_Reference/register_post_type)

Args
----

[](#args)

NameTypeRequiredDescriptionDefault[labels](#Labels)arraynoAn array of labels for this post type. By default, post labels are used for non-hierarchical post types and page labels for hierarchical onesif empty, `name` is set to value of `label`, and `singular_name` is set to value of `name`publicbooleannoControls how the type is visible to authors `(show_in_nav_menus, show_ui)` and readers `(exclude_from_search, publicly_queryable)`falsepublicly\_queryablebooleannoWhether queries can be performed on the front end as part of parse\_request()value of `public` argumentshow\_uibooleannoWhether to generate a default UI for managing this post type in the adminvalue of `public` argumentshow\_in\_menuboolean/stringnoWhere to show the post type in the admin menu. `show_ui` must be `true`value of `show_ui` argumenthas\_archiveboolean/stringnoEnables post type archives. Will use $post\_type as archive slug by defaultfalsesupportsarray/booleannoAn alias for calling [add\_post\_type\_support()](https://codex.wordpress.org/Function_Reference/add_post_type_support) directly. As of [3.5](https://codex.wordpress.org/Version_3.5), boolean **false** can be passed as value instead of an array to prevent default (title and editor) behaviortitle and editorLabels
------

[](#labels)

NameDescriptionDefaultnamegeneral name for the post type, usually plural. The same and overridden by $post\_type\_object-&gt;labelPosts/Pagessingular\_namename for one object of this post typePost/Pageadd\_newthe add new textThe default is **Add New**add\_new\_itemthe add new textDefault is **Add New Post/Add New Page**edit\_item-Default is **Edit Post/Edit Page**new\_item-Default is **New Post/New Page**view\_item-Default is **View Post/View Page**view\_itemsLabel for viewing post type archivesDefault is **View Posts / View Pages**search\_items-Default is **Search Posts/Search Pages**not\_found-Default is **No posts found/No pages found**not\_found\_in\_trash-Default is **No posts found in Trash/No pages found in Trash**parent\_item\_colonThis string isn't used on non-hierarchical typesIn hierarchical ones the default is **Parent Page:**all\_itemsString for the submenuDefault is **All Posts/All Pages**archivesString for use with archives in nav menusDefault is **Post Archives/Page Archives**attributesLabel for the attributes meta boxDefault is **Post Attributes / Page Attributes**insert\_into\_itemString for the media frame buttonDefault is **Insert into post/Insert into page**uploaded\_to\_this\_itemString for the media frame filterDefault is **Uploaded to this post/Uploaded to this page**featured\_image-Default is **Featured Image**set\_featured\_image-Default is **Set featured image**use\_featured\_image-Default is **Use as featured image**menu\_name-Default is the same as **name**filter\_items\_listString for the table views hidden heading-items\_list\_navigationString for the table pagination hidden heading-items\_listString for the table hidden heading-name\_admin\_barString for use in New in Admin menu barDefault is the same as **singular\_name**Usage
=====

[](#usage)

1. Use alias function
---------------------

[](#1-use-alias-function)

```
registerCpter('book', 'Book', 'Books');

```

2. Create a CPT child class
---------------------------

[](#2-create-a-cpt-child-class)

### Register a custom post type with default arguments

[](#register-a-custom-post-type-with-default-arguments)

```
$book = new Vietfreshair\CPT('book', 'Book', 'Books');
```

### Register a custom post type with specific arguments

[](#register-a-custom-post-type-with-specific-arguments)

```
$song = new Vietfreshair\CPT(
    'song',
    'Song',
    'Songs',
    ['menu_icon' => 'dashicons-format-audio']
);
```

### Register a custom post type with meta fields

[](#register-a-custom-post-type-with-meta-fields)

**NOTE:** We are using CMB2 to create meta fields for custom post type. See [here](https://github.com/WebDevStudios/CMB2/wiki/Basic-Usage) to find out how to use CMB2. You can see a list of available field types [here](https://github.com/WebDevStudios/CMB2/wiki/Field-Types#types).

```
$book->registerMetafields(
	[
		[
	        'id'            => 'test_metabox',
	        'title'         => __( 'Test Metabox', 'cmb2' ),
	        'context'       => 'normal',
	        'priority'      => 'high',
	        'show_names'    => true, // Show field names on the left
	        // 'cmb_styles' => false, // false to disable the CMB stylesheet
	        // 'closed'     => true, // Keep the metabox closed by default
	        'fields'        => [
	        	[
			        'name' => __( 'Website URL', 'cmb2' ),
			        'desc' => __( 'field description (optional)', 'cmb2' ),
			        'id'   => 'url',
			        'type' => 'text_url',
			    ],
			    [
			        'name' => __( 'Test Text Email', 'cmb2' ),
			        'desc' => __( 'field description (optional)', 'cmb2' ),
			        'id'   => 'email',
			        'type' => 'text_email',
			        // 'repeatable' => true,
			    ]
	        ]
		],
		[
	        'id'            => 'test_metabox_2',
	        'title'         => __( 'Test Metabox', 'cmb2' ),
	        'context'       => 'normal',
	        'priority'      => 'high',
	        'show_names'    => true, // Show field names on the left
	        // 'cmb_styles' => false, // false to disable the CMB stylesheet
	        // 'closed'     => true, // Keep the metabox closed by default
	        'fields'        => [
	        	[
			        'name' => __( 'Website URL', 'cmb2' ),
			        'desc' => __( 'field description (optional)', 'cmb2' ),
			        'id'   => 'url',
			        'type' => 'text_url',
			    ],
			    [
			        'name' => __( 'Test Text Email', 'cmb2' ),
			        'desc' => __( 'field description (optional)', 'cmb2' ),
			        'id'   => 'email',
			        'type' => 'text_email',
			        // 'repeatable' => true,
			    ]
	        ]
		]
	]
);
```

Changelog
=========

[](#changelog)

1.2.2

- Required cmb2 package

1.2.1

- Fixed CMB2 issue #12

1.2.0

- Add alias function for creating custom post type object
- Change namespace

1.1.0

- Change structure

1.0.0

- First init

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 94.9% 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

Every ~67 days

Total

2

Last Release

3362d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/871d2fe27b5a4b23bd86ecfeeb7ab0d04276a1d41d0fdd37b09665c315ff2e21?d=identicon)[vietfreshair](/maintainers/vietfreshair)

---

Top Contributors

[![duyngha](https://avatars.githubusercontent.com/u/8712540?v=4)](https://github.com/duyngha "duyngha (56 commits)")[![vietfreshair](https://avatars.githubusercontent.com/u/23194738?v=4)](https://github.com/vietfreshair "vietfreshair (3 commits)")

### Embed Badge

![Health badge](/badges/vietfreshair-cpt/health.svg)

```
[![Health](https://phpackages.com/badges/vietfreshair-cpt/health.svg)](https://phpackages.com/packages/vietfreshair-cpt)
```

PHPackages © 2026

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