Register a Portfolio Post Type

How to create a custom post type that can be used as a portfolio. You can also add custom categories to your new post types.

/**
 * Register custom post types
 *
 * @since 1.0
 */

function my_custom_post_types() {

	register_post_type( 'portfolio', array(
		'public'        => true,
		'menu_position' => 20,
		'taxonomies'    => array( 'portfolio_category' ),
		'has_archive'   => false,
		'supports'      => array( 'title', 'editor', 'thumbnail' ),
		'labels'        => array(
			'name'               => 'Portfolio',
			'singular_name'      => 'Portfolio',
			'menu_name'          => 'Portfolio',
			'name_admin_bar'     => 'Portfolio',
			'add_new_item'       => 'Add New Portfolio Item',
			'edit_item'          => 'Edit Portfolio Item',
			'new_item'           => 'New Portfolio Item',
			'view_item'          => 'View Portfolio Item',
			'search_items'       => 'Search Portfolio',
			'not_found'          => 'Nothing found',
			'not_found_in_trash' => 'Nothing found in trash',
			'all_items'          => 'View All'
		)
	) );

}

add_action( 'init', 'my_custom_post_types', 1 );


/**
 * Create taxonomies to associate with post type.
 *
 * @since 1.0
 */

function my_custom_taxonomies() {

	register_taxonomy( 'portfolio_category', 'portfolio', array(
		'hierarchical' => true,
		'show_ui'      => true,
		'query_var'    => true,
		'rewrite'      => array(
			'slug'         => 'portfolio/category',
			'with_front'   => false,
			'hierarchical' => true
		),
		'capabilities' => array( 'manage_categories' )
	) );

}

add_action( 'init', 'my_custom_taxonomies', 0 );

Leave a Comment