PostType
Register custom post types with ease.
Usage
use WPDev\Facades\PostType;
PostType::create('project')
->supportsPageAttributes()
->menuIcon('dashicons-hammer')
->register();
API Reference
Public Methods
Method | Summary |
__construct |
Constructor. For more fluid syntax use PostType::create()
|
canExport | Whether or not the post_type can be exported Default: true |
create
static |
For a more fluid syntax. |
deleteWithUser | Whether to delete posts of this type when deleting a user. If true, posts of this type belonging to the user will be moved to trash when then user is deleted. If false, posts of this type belonging to the user will not be trashed or deleted. If not set (the default), posts are trashed if post_type_supports('author'). Otherwise posts are not trashed or deleted. |
deregister | Deregisters the post type. |
hasArchive | Enables post type archives. Will use $post_type as archive slug by default. |
permalinkEPMask |
This sets the endpoint mask. However rewrite['ep_mask'] takes precedence if it's set there too.
|
queryVar | True (default) will use the post type slug False disables query_var key use. A post type cannot be loaded at /?{query_var}={single_post_slug} A string essentially overrides the post type slug /?{query_var_string}={single_post_slug} |
registerManually | Use this method if you want to take care of all the hooks. |
register | Registers the post type. Hooks and all. |
registerMetaBoxCB | Provide a callback function that will be called when setting up the meta boxes for the edit form. |
restBase | The base slug that this post type will use when accessed using the REST API. |
restControllerClass |
An optional custom controller to use instead of WP_REST_Posts_Controller . Must be a subclass of WP_REST_Controller .
|
rewrite |
Set the rewrite arg.
|
setArg | Set an arg. Can be used to override the defaults. |
showInRest |
Whether to expose this post type in the REST API .
|
excludeFromSearch | Exclude from search results |
hierarchical | Whether the post type is hierarchical (e.g. page). |
mapMetaCap | Whether to use the internal default meta capability handling. |
menuIcon | The menu icon. |
menuPosition | The position in the menu order the post type should appear. |
removeSupport | Removes a supports arg. Use this to remove one of the defaults. |
setPluralName | Set the plural name. Useful if simply appending an 's' isn't grammatically correct. |
public |
Sets the public arg.
|
publiclyQueryable | Whether queries can be performed on the front end as part of parse_request(). |
showInAdminBar | Whether to make this post type available in the WordPress admin bar. |
showInMenu | Show this post type in the menu. |
showInNavMenus | Post type is available for selection in navigation menus. |
showUI | Whether to generate a default UI for managing this post type in the admin. |
setSingularName | Overrides auto generated singular name. |
supportsAuthor | Support author. |
supportsComments | Support comments. |
supportsCustomFields | Support custom fields. |
supportsEditor | Support editor. |
supportsExcerpt | Support excerpt. |
supportsFeaturedImage | Support featured image (aka thumbnail). |
supportsPageAttributes | Support page attributes. |
supportsPostFormats | Support post formats. |
supportsRevisions | Support revisions. |
supportsThumbnail |
Alternative to @see supportsFeaturedImage . Support featured image (aka thumbnail).
|
supportsTitle | Support title. |
supportsTrackbacks | Support trackbacks. |
supports | False can be passed as value instead of an array to prevent default (title and editor) behavior |
taxonomies | An array of registered taxonomies like category or post_tag that will be used with this post type. |
-
__construct
__construct( string
$name
)SummaryConstructor. For more fluid syntax usePostType::create()
ParametersnameThe name of the post type. Should be singular. -
canExport
canExport( [ bool
$bool
] )SummaryWhether or not the post_type can be exported Default: trueParametersboolReturns$this
-
create
create( string
$name
)SummaryFor a more fluid syntax.ParametersnameReturns$this
-
deleteWithUser
deleteWithUser( [ bool
$bool
] )SummaryWhether to delete posts of this type when deleting a user. If true, posts of this type belonging to the user will be moved to trash when then user is deleted. If false, posts of this type belonging to the user will not be trashed or deleted. If not set (the default), posts are trashed if post_type_supports('author'). Otherwise posts are not trashed or deleted.ParametersboolReturns$this
-
deregister
deregister( )
SummaryDeregisters the post type.Returnsbool | \WP_Error
-
hasArchive
hasArchive( [ bool | string
$val
] )SummaryEnables post type archives. Will use $post_type as archive slug by default.ParametersvalReturns$this
-
permalinkEPMask
permalinkEPMask( int
$endpoint
)SummaryThis sets the endpoint mask. Howeverrewrite['ep_mask']
takes precedence if it's set there too.ParametersendpointConstant preferred to avoid future failure (core updates)Returns$this
-
queryVar
queryVar( [ bool | string
$query_var
] )SummaryTrue (default) will use the post type slug False disables query_var key use. A post type cannot be loaded at /?{query_var}={single_post_slug} A string essentially overrides the post type slug /?{query_var_string}={single_post_slug}Parametersquery_varReturns$this
-
registerManually
registerManually( )
SummaryUse this method if you want to take care of all the hooks.Returns\WP_Error | \WP_Post_Type
-
register
register( )
SummaryRegisters the post type. Hooks and all.Returns$this
-
registerMetaBoxCB
registerMetaBoxCB( callable
$callback
)SummaryProvide a callback function that will be called when setting up the meta boxes for the edit form.ParameterscallbackReturns$this
-
restBase
restBase( string
$rest_base
)SummaryThe base slug that this post type will use when accessed using the REST API.Parametersrest_baseReturns$this
-
restControllerClass
restControllerClass( [ string
$controller
] )SummaryAn optional custom controller to use instead ofWP_REST_Posts_Controller
. Must be a subclass ofWP_REST_Controller
.ParameterscontrollerReturns$this
-
rewrite
rewrite( [ array | bool
$val
] )SummarySet therewrite
arg.Parametersval(see above)Returns$this
-
setArg
setArg( [ string
$key
, mixed$val
] )SummarySet an arg. Can be used to override the defaults.ParameterskeyvalReturns$this
-
showInRest
showInRest( [ bool
$bool
] )SummaryWhether to expose this post type in theREST API
.ParametersboolReturns$this
-
excludeFromSearch
excludeFromSearch( [ bool
$bool
] )SummaryExclude from search resultsParametersboolReturns$this
-
hierarchical
hierarchical( [ bool
$bool
] )SummaryWhether the post type is hierarchical (e.g. page).ParametersboolReturns$this
-
mapMetaCap
mapMetaCap( [ bool
$bool
] )SummaryWhether to use the internal default meta capability handling.ParametersboolReturns$this
-
removeSupport
removeSupport( int | string
$feature
)SummaryRemoves a supports arg. Use this to remove one of the defaults.ParametersfeatureThe feature to remove.Returns$this
-
setPluralName
setPluralName( [ string
$plural_name
] )SummarySet the plural name. Useful if simply appending an 's' isn't grammatically correct.Parametersplural_nameReturns$this
-
public
public( [ bool
$bool
] )SummarySets thepublic
arg.ParametersboolReturns$this
-
publiclyQueryable
publiclyQueryable( [ bool
$bool
] )SummaryWhether queries can be performed on the front end as part of parse_request().ParametersboolReturns$this
-
showInAdminBar
showInAdminBar( [ bool
$bool
] )SummaryWhether to make this post type available in the WordPress admin bar.ParametersboolReturns$this
-
showInMenu
showInMenu( [ bool | string
$val
] )SummaryShow this post type in the menu.Parametersval- If string is given it will be a submenu if that url exists. Examples: 'tools.php' or 'edit.php?post_type=page';Returns$this
-
showUI
showUI( [ bool
$bool
] )SummaryWhether to generate a default UI for managing this post type in the admin.ParametersboolReturns$this
-
setSingularName
setSingularName( [ string
$singular_name
] )SummaryOverrides auto generated singular name.Parameterssingular_nameReturns$this
-
supportsAuthor
supportsAuthor( [ bool
$add
] )SummarySupport author.ParametersaddTrue (default) to add, False to remove.Returns$this
-
supportsComments
supportsComments( [ bool
$add
] )SummarySupport comments.ParametersaddTrue (default) to add, False to remove.Returns$this
-
supportsCustomFields
supportsCustomFields( [ bool
$add
] )SummarySupport custom fields.ParametersaddTrue (default) to add, False to remove.Returns$this
-
supportsEditor
supportsEditor( [ bool
$add
] )SummarySupport editor.ParametersaddTrue (default) to add, False to remove.Returns$this
-
supportsExcerpt
supportsExcerpt( [ bool
$add
] )SummarySupport excerpt.ParametersaddTrue (default) to add, False to remove.Returns$this
-
supportsFeaturedImage
supportsFeaturedImage( [ bool
$add
] )SummarySupport featured image (aka thumbnail).ParametersaddTrue (default) to add, False to remove.Returns$this
-
supportsPageAttributes
supportsPageAttributes( [ bool
$add
] )SummarySupport page attributes.ParametersaddTrue (default) to add, False to remove.Returns$this
-
supportsPostFormats
supportsPostFormats( [ bool
$add
] )SummarySupport post formats.ParametersaddTrue (default) to add, False to remove.Returns$this
-
supportsRevisions
supportsRevisions( [ bool
$add
] )SummarySupport revisions.ParametersaddTrue (default) to add, False to remove.Returns$this
-
supportsThumbnail
supportsThumbnail( [ bool
$add
] )SummaryAlternative to@see supportsFeaturedImage
. Support featured image (aka thumbnail).ParametersaddTrue (default) to add, False to remove.Returns$this
-
supportsTitle
supportsTitle( [ bool
$add
] )SummarySupport title.ParametersaddTrue (default) to add, False to remove.Returns$this
-
supportsTrackbacks
supportsTrackbacks( [ bool
$add
] )SummarySupport trackbacks.ParametersaddTrue (default) to add, False to remove.Returns$this
-
supports
supports( array | bool | string
$features
)SummaryFalse can be passed as value instead of an array to prevent default (title and editor) behaviorParametersfeaturesReturns$this
-
taxonomies
taxonomies( [ array
$taxonomies
] )SummaryAn array of registered taxonomies like category or post_tag that will be used with this post type.ParameterstaxonomiesReturns$this