我想在我的WordPress站点中自定义帖子类型。为此,我使用了register_post_type
my中的方法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\' );
SO网友:Owais Alam
尝试以下代码添加多个自定义帖子类型
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\' );