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 )

    Summary
    Constructor. For more fluid syntax use PostType::create()
    Parameters
    name
    The name of the post type. Should be singular.
  • canExport

    canExport( [ bool $bool ] )

    Summary
    Whether or not the post_type can be exported Default: true
    Parameters
    bool
    Returns

    $this

  • create

    create( string $name )

    Summary
    For a more fluid syntax.
    Parameters
    name
    Returns

    $this

  • deleteWithUser

    deleteWithUser( [ bool $bool ] )

    Summary
    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.
    Parameters
    bool
    Returns

    $this

  • deregister

    deregister( )

    Summary
    Deregisters the post type.
    Returns

    bool | \WP_Error

  • hasArchive

    hasArchive( [ bool | string $val ] )

    Summary
    Enables post type archives. Will use $post_type as archive slug by default.
    Parameters
    val
    Returns

    $this

  • permalinkEPMask

    permalinkEPMask( int $endpoint )

    Summary
    This sets the endpoint mask. However rewrite['ep_mask'] takes precedence if it's set there too.
    Parameters
    endpoint
    Constant preferred to avoid future failure (core updates)
    Returns

    $this

  • queryVar

    queryVar( [ bool | string $query_var ] )

    Summary
    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}
    Parameters
    query_var
    Returns

    $this

  • registerManually

    registerManually( )

    Summary
    Use this method if you want to take care of all the hooks.
    Returns

    \WP_Error | \WP_Post_Type

  • register

    register( )

    Summary
    Registers the post type. Hooks and all.
    Returns

    $this

  • registerMetaBoxCB

    registerMetaBoxCB( callable $callback )

    Summary
    Provide a callback function that will be called when setting up the meta boxes for the edit form.
    Parameters
    callback
    Returns

    $this

  • restBase

    restBase( string $rest_base )

    Summary
    The base slug that this post type will use when accessed using the REST API.
    Parameters
    rest_base
    Returns

    $this

  • restControllerClass

    restControllerClass( [ string $controller ] )

    Summary
    An optional custom controller to use instead of WP_REST_Posts_Controller. Must be a subclass of WP_REST_Controller.
    Parameters
    controller
    Returns

    $this

  • rewrite

    rewrite( [ array | bool $val ] )

    Summary
    Set the rewrite arg.
    Parameters
    val
    (see above)
    Returns

    $this

  • setArg

    setArg( [ string $key, mixed $val ] )

    Summary
    Set an arg. Can be used to override the defaults.
    Parameters
    key
    val
    Returns

    $this

  • showInRest

    showInRest( [ bool $bool ] )

    Summary
    Whether to expose this post type in the REST API.
    Parameters
    bool
    Returns

    $this

  • excludeFromSearch

    excludeFromSearch( [ bool $bool ] )

    Summary
    Exclude from search results
    Parameters
    bool
    Returns

    $this

  • hierarchical

    hierarchical( [ bool $bool ] )

    Summary
    Whether the post type is hierarchical (e.g. page).
    Parameters
    bool
    Returns

    $this

  • mapMetaCap

    mapMetaCap( [ bool $bool ] )

    Summary
    Whether to use the internal default meta capability handling.
    Parameters
    bool
    Returns

    $this

  • menuIcon

    menuIcon( [ string $icon ] )

    Summary
    The menu icon.
    Parameters
    icon
    name of Dashicon, URL to icon, or base64 encoded svg with fill="black"
    Returns

    $this

  • menuPosition

    menuPosition( [ int $position ] )

    Summary
    The position in the menu order the post type should appear.
    Parameters
    position
    Returns

    $this

  • removeSupport

    removeSupport( int | string $feature )

    Summary
    Removes a supports arg. Use this to remove one of the defaults.
    Parameters
    feature
    The feature to remove.
    Returns

    $this

  • setPluralName

    setPluralName( [ string $plural_name ] )

    Summary
    Set the plural name. Useful if simply appending an 's' isn't grammatically correct.
    Parameters
    plural_name
    Returns

    $this

  • public

    public( [ bool $bool ] )

    Summary
    Sets the public arg.
    Parameters
    bool
    Returns

    $this

  • publiclyQueryable

    publiclyQueryable( [ bool $bool ] )

    Summary
    Whether queries can be performed on the front end as part of parse_request().
    Parameters
    bool
    Returns

    $this

  • showInAdminBar

    showInAdminBar( [ bool $bool ] )

    Summary
    Whether to make this post type available in the WordPress admin bar.
    Parameters
    bool
    Returns

    $this

  • showInMenu

    showInMenu( [ bool | string $val ] )

    Summary
    Show this post type in the menu.
    Parameters
    val
    - If string is given it will be a submenu if that url exists. Examples: 'tools.php' or 'edit.php?post_type=page';
    Returns

    $this

  • showInNavMenus

    showInNavMenus( [ bool $bool ] )

    Summary
    Post type is available for selection in navigation menus.
    Parameters
    bool
    Returns

    $this

  • showUI

    showUI( [ bool $bool ] )

    Summary
    Whether to generate a default UI for managing this post type in the admin.
    Parameters
    bool
    Returns

    $this

  • setSingularName

    setSingularName( [ string $singular_name ] )

    Summary
    Overrides auto generated singular name.
    Parameters
    singular_name
    Returns

    $this

  • supportsAuthor

    supportsAuthor( [ bool $add ] )

    Summary
    Support author.
    Parameters
    add
    True (default) to add, False to remove.
    Returns

    $this

  • supportsComments

    supportsComments( [ bool $add ] )

    Summary
    Support comments.
    Parameters
    add
    True (default) to add, False to remove.
    Returns

    $this

  • supportsCustomFields

    supportsCustomFields( [ bool $add ] )

    Summary
    Support custom fields.
    Parameters
    add
    True (default) to add, False to remove.
    Returns

    $this

  • supportsEditor

    supportsEditor( [ bool $add ] )

    Summary
    Support editor.
    Parameters
    add
    True (default) to add, False to remove.
    Returns

    $this

  • supportsExcerpt

    supportsExcerpt( [ bool $add ] )

    Summary
    Support excerpt.
    Parameters
    add
    True (default) to add, False to remove.
    Returns

    $this

  • supportsFeaturedImage

    supportsFeaturedImage( [ bool $add ] )

    Summary
    Support featured image (aka thumbnail).
    Parameters
    add
    True (default) to add, False to remove.
    Returns

    $this

  • supportsPageAttributes

    supportsPageAttributes( [ bool $add ] )

    Summary
    Support page attributes.
    Parameters
    add
    True (default) to add, False to remove.
    Returns

    $this

  • supportsPostFormats

    supportsPostFormats( [ bool $add ] )

    Summary
    Support post formats.
    Parameters
    add
    True (default) to add, False to remove.
    Returns

    $this

  • supportsRevisions

    supportsRevisions( [ bool $add ] )

    Summary
    Support revisions.
    Parameters
    add
    True (default) to add, False to remove.
    Returns

    $this

  • supportsThumbnail

    supportsThumbnail( [ bool $add ] )

    Summary
    Alternative to @see supportsFeaturedImage. Support featured image (aka thumbnail).
    Parameters
    add
    True (default) to add, False to remove.
    Returns

    $this

  • supportsTitle

    supportsTitle( [ bool $add ] )

    Summary
    Support title.
    Parameters
    add
    True (default) to add, False to remove.
    Returns

    $this

  • supportsTrackbacks

    supportsTrackbacks( [ bool $add ] )

    Summary
    Support trackbacks.
    Parameters
    add
    True (default) to add, False to remove.
    Returns

    $this

  • supports

    supports( array | bool | string $features )

    Summary
    False can be passed as value instead of an array to prevent default (title and editor) behavior
    Parameters
    features
    Returns

    $this

  • taxonomies

    taxonomies( [ array $taxonomies ] )

    Summary
    An array of registered taxonomies like category or post_tag that will be used with this post type.
    Parameters
    taxonomies
    Returns

    $this