steven-r
10/20/2017 - 3:48 PM

custom post type

Code for creating a custom post type pluggin

<?php 

/**
Plugin Name: [NAME HERE]
Description: [DESC HERE]
Version: 3.0.1
License: GPLv2
*/

function custom_post_type() {

	$single = "Testimonial";
	$plural = "Testimonials";
	// set up labels
	$labels = array(
 		'name' => $plural,
    	'singular_name' => $single,
    	'add_new' => 'Add New ' . $single,
    	'add_new_item' => 'Add New ' . $single,
    	'edit_item' => 'Edit ' . $single,
    	'new_item' => 'New ' . $single,
    	'all_items' => 'All '. $plural,
    	'view_item' => 'View ' . $single,
    	'search_items' => 'Search ' . $plural,
    	'not_found' =>  'No ' . $plural .' Found',
    	'not_found_in_trash' => 'No ' . $plural .' found in Trash', 
    	'parent_item_colon' => '',
    	'menu_name' => $plural,
    );
    //register post type
	register_post_type( 'testimonials', array(
		'labels' => $labels,
		'has_archive' => true,
 		'public' => true,
		'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail','page-attributes' ),
		'taxonomies' => array( 'post_tag', 'category' ),
		'menu_icon' => 'dashicons-welcome-comments',	
		'exclude_from_search' => false,
		'capability_type' => 'post',
		'rewrite' => array( 'slug' => $plural),
		)
	);
}
add_action( 'init', 'custom_post_type' );

?>