Snippets

Joey Hernandez WordPress - Sample Custom Post Type

Created by Joey Hernandez
<?php
/**
 * Custom Post Types | {Type}
 * @link http://codex.wordpress.org/Function_Reference/register_post_type
 * @link http://themergency.com/generators/wordpress-custom-post-types/
 */
class ProjectPrefix_CPT_Type {

	static $instance	= false;

	public function __construct() {

		$this->projectprefix_cpt_type();

	}


	protected function projectprefix_cpt_type() {
		$labels = array(
			'name'               => _x( 'Custom_Post_Type', 'post type general name' ),
			'singular_name'      => _x( 'Custom_Post_Type', 'post type singular name' ),
			'add_new'            => _x( 'Add New', 'Custom_Post_Type' ),
			'add_new_item'       => __( 'Add Custom_Post_Type' ),
			'edit_item'          => __( 'Edit Custom_Post_Type' ),
			'new_item'           => __( 'New Custom_Post_Type' ),
			'all_items'          => __( 'All Custom_Post_Types' ),
			'view_item'          => __( 'View Custom_Post_Type' ),
			'search_items'       => __( 'Search Custom_Post_Types' ),
			'not_found'          => __( 'No Custom_Post_Types Found' ),
			'not_found_in_trash' => __( 'No Custom_Post_Types Found in the Trash' ),
			'parent_item_colon'  => '',
			'menu_name'          => _x( 'Custom_Post_Types', 'admin menu' )
		);
		$args = array(
			'labels'			=> $labels,
			'description'		=> 'Custom_Post_Types',
			'public'			=> true,
			'menu_position'		=> 25,
			'supports'			=> array( 'author', 'title', 'thumbnail', 'category', 'editor' ),
			'has_archive'		=> true,
			'menu_icon'			=> 'dashicons-admin-users',
			'show_in_nav_menus'	=> true,
			'query_var'			=> true,
			'can_export'		=> true,
			// 'rewrite'			=> false,
			'capability_type'	=> 'post',
		);
		register_post_type( 'post_type_name', $args );

	}


	/**
	 * Singleton
	 *
	 * Returns a single instance of the current class.
	 */
	public static function singleton() {

		if ( ! self::$instance )
			self::$instance	= new self;

		return self::$instance;
	}

}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.