Skip to content

Instantly share code, notes, and snippets.

@marcjenkins
Created July 12, 2017 08:31
Show Gist options
  • Save marcjenkins/b629950566c32c44699847fa53cee0ed to your computer and use it in GitHub Desktop.
Save marcjenkins/b629950566c32c44699847fa53cee0ed to your computer and use it in GitHub Desktop.
Create a post type in WP
<?php
/**
* Custom Post Types
* Icon reference: https://developer.wordpress.org/resource/dashicons/#editor-textcolor
* Uncomment add_action to enable
*/
// add_action('init', 'origin_cpts');
function origin_cpts() {
$post_type_name = "products";
$single_name = "Product";
$plural_name = "Products";
$icon = "dashicons-cart";
$post_type_options = array(
'label' => $single_name,
'public' => true,
'menu_icon' => $icon,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'hierarchical' => true,
'rewrite' => array(
'slug' => '',
'with_front' => '0'
),
'query_var' => true,
'has_archive' => true,
'supports' => array(
'title',
'editor',
'revisions',
'thumbnail',
'author',
'page-attributes',
),
'labels' => array(
'name' => $single_name,
'singular_name' => $single_name,
'menu_name' => $plural_name,
'add_new' => 'Add ' . $single_name,
'add_new_item' => 'Add New ' . $single_name,
'edit' => 'Edit',
'edit_item' => 'Edit ' . $single_name,
'new_item' => 'New '. $single_name,
'view' => 'View '. $single_name,
'view_item' => 'View '. $single_name,
'search_items' => 'Search ' . $plural_name,
'not_found' => 'No '. $plural_name . ' Found',
'not_found_in_trash' => 'No '. $plural_name .' Found in Trash',
'parent' => 'Parent '. $single_name
),
);
register_post_type($post_type_name, $post_type_options);
// $post_type_name = "testimonials";
// $single_name = "Testimonial";
// $plural_name = "Testimonials";
// $icon = "dashicons-cart";
// $post_type_options = array(
// 'label' => $single_name,
// 'public' => true,
// 'menu_icon' => $icon,
// 'show_ui' => true,
// 'show_in_menu' => true,
// 'capability_type' => 'post',
// 'hierarchical' => true,
// 'rewrite' => array(
// 'slug' => '',
// 'with_front' => '0'
// ),
// 'query_var' => true,
// 'has_archive' => true,
// 'supports' => array(
// 'title',
// 'editor',
// 'revisions',
// 'thumbnail',
// 'author',
// 'page-attributes',
// ),
// 'labels' => array(
// 'name' => $single_name,
// 'singular_name' => $single_name,
// 'menu_name' => $plural_name,
// 'add_new' => 'Add ' . $single_name,
// 'add_new_item' => 'Add New ' . $single_name,
// 'edit' => 'Edit',
// 'edit_item' => 'Edit ' . $single_name,
// 'new_item' => 'New '. $single_name,
// 'view' => 'View '. $single_name,
// 'view_item' => 'View '. $single_name,
// 'search_items' => 'Search ' . $plural_name,
// 'not_found' => 'No '. $plural_name . ' Found',
// 'not_found_in_trash' => 'No '. $plural_name .' Found in Trash',
// 'parent' => 'Parent '. $single_name
// ),
// );
// register_post_type($post_type_name, $post_type_options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment