Documentation / Tutorials / Triggers
Creating Custom Post Types (CPT)
/ Triggers / Creating Custom Post Types (CPT)
CPT is made up of 3 parts. The cpt itself, taxonomy and meta fields
Defining Post type
Here you need to define the cpt details like singular_label, plural_label and slug. You can customize the other parameters as per need.
module.singular_label: Singular name of post type
module.plural_label: Plural name of post type
post slug: CPT slug (max. 20 characters, cannot contain capital letters or spaces)
[aw2.set module.singular_label='name' /]
[aw2.set module.plural_label='names' /]
[aw2.register post slug='your-cpt-slug']
{
"label" : "[aw2.get module.plural_label /]",
"public" : true,
"exclude_from_search":true,
"publicly_queryable":false,
"show_in_nav_menus":false,
"show_ui" : true,
"show_in_menu" : true,
"capability_type" : "post",
"map_meta_cap" : true,
"hierarchical" : false,
"query_var" : true,
"supports" : [ "title","editor","page-attributes","thumbnail" ],
"rewrite" : {"slug":"testimonial"},
"labels" : {
"name" : "[aw2.get module.plural_label /]",
"singular_name" : "[aw2.get module.singular_label /]",
"menu_name" : "[aw2.get module.plural_label /]",
"add_new" : "Add [aw2.get module.singular_label /]",
"add_new_item" : "Add New [aw2.get module.singular_label /]",
"edit" : "Edit",
"edit_item" : "Edit [aw2.get module.singular_label /]",
"new_item" : "New [aw2.get module.singular_label /]",
"view" : "View [aw2.get module.singular_label /]",
"view_item" : "View [aw2.get module.singular_label /]",
"search_items" : "Search [aw2.get module.plural_label /]",
"not_found" : "No [aw2.get module.plural_label /] Found",
"not_found_in_trash" : "No [aw2.get module.plural_label /] Found in Trash",
"parent" : "Parent [aw2.get module.singular_label /]"
}
}
[/aw2.register]
Taxonomy
module.singular_label: Singular name of taxonomy
module.plural_label: Plural name of taxonomy
post slug: CPT slug
Note: taxonomy slug and post_type slug names should be unique.
[aw2.set module.singular_label='Category' /]
[aw2.set module.plural_label='categories' /]
[aw2.register taxonomy slug='as_category_slug' post_type='as_category']
{
"label" :"[aw2.get module.plural_label /]",
"hierarchical" : true,
"show_ui":true,
"show_admin_column":false,
"show_in_nav_menus":false,
"query_var" : true,
"rewrite" : true,
"labels" : {
"name" : "[aw2.get module.plural_label /]",
"singular_name" : "[aw2.get module.singular_label /]",
"menu_name" : "[aw2.get module.plural_label /]",
"add_new" : "Add [aw2.get module.singular_label /]",
"add_new_item" : "Add New [aw2.get module.singular_label /]",
"edit" : "Edit",
"edit_item" : "Edit [aw2.get module.singular_label /]",
"new_item" : "New [aw2.get module.singular_label /]",
"view" : "View [aw2.get module.singular_label /]",
"view_item" : "View [aw2.get module.singular_label /]",
"search_items" : "Search [aw2.get module.plural_label /]",
"not_found" : "No [aw2.get module.plural_label /] Found"
}
}
[/aw2.register]
Meta
You can create as many meta fields you need. Use the following code
Meta ID:
id:
title:
object_types
field id:
name:
id:
type:
[aw2.register metabox part=start id=name]
{
"id" :"name",
"title" :"Title for meta",
"object_types" : [ "your CPT slug" ],
"context" :"normal",
"priority" :"high",
"show_names" : true
}
[/aw2.register]
[aw2.register metabox part=field id=Surname]
{
"name":"Your Surname",
"id" : "surname",
"type":"text"
}
[/aw2.register]