Skip to content

Post Types

Noah Mason edited this page Dec 22, 2022 · 13 revisions

WP Backstage can create new custom post types with deeply integrated custom fields.

Arguments

  • singular_name string ― The post type's singular name.
  • plural_name string ― The post type's plural name.
  • thumbnail_label string ― The post type's thumbnail (or featured image) label.
  • description string ― The post type's description.
  • menu_name string ― The post type's menu name as displayed in the admin menu. If omitted, this will default to the "plural_name" argument.
  • menu_icon string ― The post type's Dashicon.
  • singular_base string ― The singular post type's URL base.
  • archive_base string ― The post type's archive URL base.
  • rest_base string ― The post type's REST API endpoint base. If omitted, this post type will be excluded from the REST API.
  • with_front bool ― Whether the post type's singular URL is prefixed with the post permalink front (all static text before the first merge tag) as set in "Settings -> Permalinks".
  • taxonomies array ― The taxonomies that have a relationship to this post type.
  • glance_item bool ― Whether this post type should be added to the "At a Glance" dashboard widget or not.
  • activity bool ― Whether this post type should be added to the "Activity" dashboard widget or not.
  • capability_type page | post ― Which capability type this post type should mimic. Use "page" to make managing this post type available to those users that can manage pages. Use "post" to make managing this post type available to those users that can manage posts.
  • supports array ― An array of default feature keys that this post type supports.
    • title ― The "Title" field on the add/edit post type screens.
    • slug ― The "Slug" meta box on the add/edit post type screens.
    • author ― The "Author" meta box on the add/edit post type screens.
    • editor ― The WYSIWYG content editor on the add/edit post type screens.
    • excerpt ― The "Excerpt" meta box on the add/edit post type screens.
    • thumbnail ― The post thumbnail functionality and the "Featured Image" meta box on the add/edit post type screens.
    • comments ― The commenting functionality and "Comments" meta box on the add/edit post type screens. If both "comments" and "trackbacks" are omitted, the "Discussion" meta box will be excluded from the add/edit post type screens.
    • trackbacks ― The native trackback and ping functionality. If both "comments" and "trackbacks" are omitted, the "Discussion" meta box will be excluded from the add/edit post type screens.
    • revisions ― The native revision functionality and "Revisions" meta box on the add/edit post type screens.
    • page-attributes ― The "Page Attributes" meta box on the add/edit post type screens. This includes the "Order" field, and on hierarchical post types, the "Parent" field.
    • custom-fields ― The "Custom Fields" meta box. This is not to be confused with WP Backstage's custom fields. Warning: editing custom fields added with this plugin through the "Custom Fields" meta box may have adverse effects, as these posted values will not run through WP Backstage's sanitization and other required functionality. To exclude any field from this meta box, prefix the field "name" with an underscore (_). This must be included in the support list for the post type's fields to be available via the REST API.
  • meta_boxes array ― An array of meta box arguments.
    • id string ― The meta box's ID.
    • title string ― The meta box's title.
    • description string ― The meta box's description.
    • context normal | side | advanced ― The meta box's default context (what meta box section of the post add/edit page this meta box should be added to).
    • priority high | default | low ― The meta box's priority (the order of the meta box in context).
    • hidden bool ― Whether the meta box is hidden by default or not. Each user can set the visibility of the meta box for themselves via the "Screen Options" panel at the top of the add/edit post type screens.
    • fields array ― The meta box's fields.

Add

WP_Backstage_Post_Type::add(
    'wp_backstage_post',
    array(
        'menu_name'     => __( 'Test Posts', 'wp_backstage_examples' ),
        'singular_name' => __( 'Test Post', 'wp_backstage_examples' ),
        'plural_name'   => __( 'Test Posts', 'wp_backstage_examples' ),
        'description'   => __( 'This is a test non-hierarchical post type.', 'wp_backstage_examples' ),
        'singular_base' => 'test-post',
        'archive_base'  => 'test-posts',
        'rest_base'     => 'test-posts',
        'taxonomies'    => array( 'category', 'post_tag' ),
        'glance_item'   => true,
        'activity'      => true,
	'supports'      => array(
		'title',
		'slug',
		'author',
		'editor',
		'excerpt',
		'thumbnail',
		'comments',
		'trackbacks',
		'revisions',
		'custom-fields',
		'page-attributes',
		'post-formats',
	),
        'meta_boxes'    => array(
            array(
                'id'          => 'wp_backstage_post_fields',
                'title'       => __( 'All Fields', 'wp_backstage_examples' ),
                'description' => __( 'These extra meta fields control further details about the test post. <a href="#">Example Link</a>', 'wp_backstage_examples' ),
                'context'     => 'normal',
                'priority'    => 'high',
                'fields'      => array(),
            ),
            array(
                'id'          => 'wp_backstage_post_extras',
                'title'       => __( 'Extras', 'wp_backstage_examples' ),
                'description' => __( 'These extra meta fields control further details about the test post. <a href="#">Example Link</a>', 'wp_backstage_examples' ),
                'context'     => 'side',
                'priority'    => 'low',
                'hidden'      => true,
                'fields'      => array(),
            ),
        ),
    )
);

Modify

WP_Backstage_Post_Type::modify(
    'post',
    array(
        'meta_boxes' => array(
            array(
                'id'          => 'wp_backstage_default_post_fields',
                'title'       => __( 'All Fields', 'wp_backstage_examples' ),
                'description' => __( 'These extra meta fields control further details about the default post. <a href="#">Example Link</a>', 'wp_backstage_examples' ),
                'context'     => 'normal',
                'priority'    => 'high',
                'fields'      => array(),
            ),
            array(
                'id'          => 'wp_backstage_default_post_extras',
                'title'       => __( 'Extras', 'wp_backstage_examples' ),
                'description' => __( 'These extra meta fields control further details about the default post. <a href="#">Example Link</a>', 'wp_backstage_examples' ),
                'context'     => 'side',
                'priority'    => 'low',
                'hidden'      => true,
                'fields'      => array(),
            ),
        ),
    )
);
Clone this wiki locally