Skip to content

Instantly share code, notes, and snippets.

@allysonsouza
Created October 7, 2014 14:35
Show Gist options
  • Save allysonsouza/b4ad992ffc68b2870aec to your computer and use it in GitHub Desktop.
Save allysonsouza/b4ad992ffc68b2870aec to your computer and use it in GitHub Desktop.
Register Post Type Example
<?php
public function create_post_type() {
$labels = array(
'name' => 'Archives',
'singular_name' => 'Archive',
'menu_name' => 'Archives',
'name_admin_bar' => 'Archives',
'add_new' => 'Add New',
'add_new_item' => 'Add New Archive',
'new_item' => 'New Archive',
'edit_item' => 'Edit Archive',
'view_item' => 'View Archive',
'all_items' => 'All Archives',
'search_items' => 'Search Archives',
'parent_item_colon' => '',
'not_found' => 'No archive found.',
'not_found_in_trash' => 'No archives found in trash.'
);
$args = array(
'labels' => $labels,
'public' => true,
'exclude_from_search'=> true,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_nav_menus' => false,
'show_in_menu' => true,
'query_var' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 60,
'has_archive' => false,
'can_export' => false,
'menu_icon' => 'dashicons-archive',
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
'capabilities' => array(
'edit_post' => true,
'edit_posts' => 'edit_posts',
'edit_others_posts' => 'edit_other_posts',
'publish_posts' => 'publish_posts',
'read_post' => 'read_post',
'read_private_posts' => 'read_private_posts',
'delete_post' => true,
'create_posts' => false,
),
'map_meta_cap' => true, //Set to false, if users are not allowed to edit/delete existing posts
);
register_post_type( 'archives', $args );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment