Я хочу создавать пользовательские типы сообщений на моем сайте WordPress. Для этого я использовал метод register_post_type
в моих functions.php
, но почему только один пользовательский тип сообщения отображается на моей странице администратора?
Код показан ниже:
function create_my_custom_posts() { register_post_type( 'career_post', array( 'labels' => array( 'name' => __( 'Careers' ), 'singular_name' => __( 'Career' ), 'add_new' => __( 'Add New' ), 'add_new_item' => __( 'Add New Career' ), 'new_item' => __( 'New Career' ), 'view_item' => __( 'View Career' ), 'search_items' => __( 'Search Careers' ), 'all_items' => __( 'All Careers' ), 'add_new_item' => __( 'Add New Career' ), 'not_found' => __( 'No Openings Yet' ) ), 'description' => 'job openings in uvionics tech', 'public' => true, 'has_archive' => true, 'menu_position' => 5 ) ); register_post_type( 'employees_comnts_post', array( 'labels' => array( 'name' => __( 'Emps Comnts' ), 'singular_name' => __( 'Emp Comnt' ), 'add_new' => __( 'Add New' ), 'add_new_item' => __( 'Add New Comnt' ), 'new_item' => __( 'New Comnt' ), 'view_item' => __( 'View Comnt' ), 'search_items' => __( 'Search Comnts' ), 'all_items' => __( 'All Comnts' ), 'add_new_item' => __( 'Add New Comnt' ), 'not_found' => __( 'No Comnts Yet' ) ), 'description' => 'Employees comments about life in company', 'public' => true, 'has_archive' => true, 'menu_position' => 5 ) ); flush_rewrite_rules( false ); } add_action( 'init', 'create_my_custom_posts' );
В документации написано, что тип сообщения должен быть макс. 20 символов, не может содержать заглавных букв или пробелов.
Попробуйте использовать следующий код для добавления нескольких настраиваемых типов сообщений
function codex_custom_init() { register_post_type( 'testimonials', array( 'labels' => array('name' => __( 'Careers' ), 'singular_name' => __( 'Career' ) ), 'public' => true, 'has_archive' => true, 'supports' => array('title', 'editor', 'thumbnail') ) ); register_post_type( 'home-messages', array( 'labels' => array('name' => __( 'Emps Comnts' ), 'singular_name' => __( 'Emp Comnt' ) ), 'public' => true, 'has_archive' => true, 'supports' => array('title', 'editor', 'thumbnail') ) ); } add_action( 'init', 'codex_custom_init' );