添加多个自定义帖子类型问题

时间:2016-04-07 作者:suhail c

我想在我的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\' );

3 个回复
最合适的回答,由SO网友:Marttin Notta 整理而成

文档中规定,帖子类型最多只能包含20个字符,不能包含大写字母或空格。

SO网友:Mahad Ali

在我的例子中,问题是我用同一个名字注册了两次,其中有不同的参数。只是需要改变post\\u类型。两种情况下的问题都是

 register_post_type(\'custom\', $arrgs); 
  register_post_type(\'custom\', $arrgs);
解决方案是以不同的方式命名post\\u类型。

   register_post_type(\'custom\', $arrgs);
   register_post_type(\'custom_2nd\', $arrgs);

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\' );

相关推荐