Skip to content

Instantly share code, notes, and snippets.

@wpjess
Created April 23, 2020 17:12
Show Gist options
  • Save wpjess/d1267a5248f28dcebd9e1fb672bb7cb9 to your computer and use it in GitHub Desktop.
Save wpjess/d1267a5248f28dcebd9e1fb672bb7cb9 to your computer and use it in GitHub Desktop.
WP create custom post type
///////////////////////////////////////////////////////////////
//////////////////// ADD POST TYPES /////////////////////////
///////////////////////////////////////////////////////////////
require_once(TEMPLATEPATH . '/post-types/slides.php');
// require_once(TEMPLATEPATH . '/post-types/another-post-type.php');
add_action("admin_init", "admin_init");
function admin_init(){ }
add_action('save_post', 'save_details');
function save_details(){
global $post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
} else { }
}
<?php
add_action('init', 'slides_register');
function slides_register() {
$labels = array(
'name' => _x('Slides', 'post type general name'),
'singular_name' => _x('Slide', 'post type singular name'),
'add_new' => _x('Add New', 'Slide'),
'add_new_item' => __('Add New Slide'),
'edit_item' => __('Edit Slide'),
'new_item' => __('New Slide'),
'view_item' => __('View Slides'),
'search_items' => __('Search Slides'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => false,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'slides', 'with_front' => true ),
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title')
);
register_post_type( 'slides' , $args );
}
// The category
register_taxonomy("slide-category", array("slides"), array("hierarchical" => true, "label" => "Categories", "singular_label" => "Category", "rewrite" => true, 'show_admin_column' => true));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment