Найти тему
IT Хищник

(WordPress) Пример использования register_post_type()

Creates a new post type or modifies an existing one:

  1. labels - An array containing the label names for the post type.
  2. menu_position - The position where the menu of the new post type should be located:
  3. public - Determines if the post type is public or not
  4. 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
  5. 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.
  6. show_in_admin_bar - Make this type available from the admin bar.
  7. showinmenu - Whether to show the post type in the admin menu and where to show the post type control. Show_ui must be enabled!
  8. 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.
  9. capability_type - A string that will be a marker for setting the rights for this post type. Inline markers are: post and page
  10. has_archive - Enable support for archive pages for this post type
  11. hierarchical - Whether records of this type will have a tree structure (like persistent pages).
  12. menu_icon - Link to the picture that will be used for this menu.
  13. can_export - The ability to export this type of records.
  14. 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);
};