register_post_type - simple example
Creates a new post type or modifies an existing one:
- labels - An array containing the label names for the post type.
- menu_position - The position where the menu of the new post type should be located:
- public - Determines if the post type is public or not
- publicly_queryable - Enables public viewing of posts of this type - this means that URL requests for this post type will work in the front-end
- show_ui - Determines whether to create logic to control the post type from the admin panel. Do I need to create a post type UI so that it can be manipulated.
- show_in_admin_bar - Make this type available from the admin bar.
- showinmenu - Whether to show the post type in the admin menu and where to show the post type control. Show_ui must be enabled!
- query_var - Sets the name of the query parameter for the post type being created. rewrite - Whether to use the CNC for this recording type. Specify false to not use the CNC. By default: true - the name of the post type is used as a prefix in the link.
- capability_type - A string that will be a marker for setting the rights for this post type. Inline markers are: post and page
- has_archive - Enable support for archive pages for this post type
- hierarchical - Whether records of this type will have a tree structure (like persistent pages).
- menu_icon - Link to the picture that will be used for this menu.
- can_export - The ability to export this type of records.
- supports - Auxiliary fields on the page for creating / editing this post type. Labels for calling the addposttype_support () function.
add_action('init', 'sales_init');
function sales_init() {
$labels = array(
'name' => __('Акции и предложения'),
'singular_name' => __('Акции'),
'add_new' => __('Добавить новый'),
'all_items' => __('Все Акции'),
'add_new_item' => __('Добавить новый'),
'edit_item' => __('Редактировать'),
'new_item' => __('Новый'),
'view_item' => __('Просмотреть'),
'search_items' => __('Поиск'),
'not_found' => __('Ничего не найдено'),
'not_found_in_trash' => __('Корзина пустая'),
'parent_item_colon' => __(''),
'menu_name' => __('Акции'),
'name_admin_bar' => 'Акции',
);
$args = array(
'labels' => $labels,
'menu_position' => 8,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_admin_bar' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_icon' => 'dashicons-info',
'hierarchical' => false,
'has_archive' => false,
'can_export' => true,
'query_var' => true,
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'revisions '),
);
register_post_type('sales', $args);
}
Written by Mad Scientist
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#