Skip to content
This repository has been archived by the owner on Oct 23, 2021. It is now read-only.

Super_Custom_Post_Type Reference

Matthew Boynes edited this page Jun 11, 2013 · 3 revisions

Super_Custom_Post_Type is a wrapper for WordPress' native register_post_type. The default arguments differ from core to make them public-facing post types (the defaults can be globally changed via the filter scpt_plugin_default_cpt_options). SuperCPT automatically sets labels, and it allows you to easily connect meta boxes and fields through Super_Custom_Post_Meta.

It's important to pay attention to which defaults are different from register_post_type:

  • 'public' => true
  • 'has_archive' => true
  • 'menu_position' => 5 (this puts post types immediately under "Posts")
  • 'supports' => array( 'title', 'editor', 'thumbnail', 'revisions', 'excerpt', 'page-attributes' )

You're not locked in to these values by any means (in fact, SuperCPT gives you five different ways to alter them), it's just important to know what you get out-of-the-box.

Method Reference

$cpt = new Super_Custom_Post_Type( $type, $singular = false, $plural = false, $register = array() )

Initialize a Custom Post Type

Parameters

string $type
The Custom Post Type slug. Should be singular, all lowercase, letters and numbers only, dashes for spaces, max 20 characters
string $singular
Optional. The singular form of our CPT to be used in menus, etc. If absent, $type gets converted to words
string $plural
Optional. The plural form of our CTP to be used in menus, etc. If absent, 's' is added to $singular
array | bool $register
Optional. If false, the CPT won't be automatically registered. If an array, can override any of the CPT defaults. See the WordPress Codex for possible values.
$cpt->connect_taxes( $taxes )

Connect this post type to one or more taxonomies

Parameters

string | array $taxes
The taxonomy/ies to connect. Pass it a 'taxonomy' or an array('tax1', 'tax2')
$cpt->set_icon( $slug )

Set a custom icon for this post type.

Parameters

string $slug
The icon slug as found in the SuperCPT Settings Page. Methods for adding custom icons coming soon.

Default Custom Post Type Settings

array(
	'label' => $this->plural,
	'labels' => array(
		'name' => _x( $this->plural, $this->type ),
		'singular_name' => _x( $this->singular, $this->type ),
		'add_new' => _x( 'New '.$this->singular, $this->type ),
		'add_new_item' => _x( 'Add New '.$this->singular, $this->type ),
		'edit_item' => _x( 'Edit '.$this->singular, $this->type ),
		'new_item' => _x( 'New '.$this->singular, $this->type ),
		'view_item' => _x( 'View '.$this->singular, $this->type ),
		'search_items' => _x( 'Search '.$this->plural, $this->type ),
		'not_found' => _x( 'No '.$this->plural.' found', $this->type ),
		'not_found_in_trash' => _x( 'No '.$this->plural.' found in Trash', $this->type ),
		'parent_item_colon' => _x( 'Parent '.$this->singular.':', $this->type ),
		'menu_name' => _x( $this->plural, $this->type ),
		),
	'description' => $this->plural,
	'public' => true,
	'publicly_queryable' => true,
	'exclude_from_search' => false,
	'show_ui' => true,
	'show_in_menu' => true,
	'menu_position' => 5, # => Below posts
	'capability_type' => 'post',
	'supports' => array( 'title', 'editor', 'thumbnail', 'revisions', 'excerpt', 'page-attributes' ),
	'has_archive' => true,
	'show_in_nav_menus' => true,
	'taxonomies' => array( ),
	# Inherited by WP defaults:
	# 'menu_icon' => "" # => Custom menu icon url goes here
	# 'hierarchical' => false,
	# 'rewrite' => true,
	# 'query_var' => true,
	# 'can_export' => true,
)