WordPress 高级自定义 Post 未在后端显示

WordPress Advanced Custom Post not displaying in backend

这是代码,第 5 个也是最后一个代码没有出现在 ADMIN CP 面板中。所有其他人都工作正常,但当我尝试添加第 5 个时。什么都没有出现。不确定是否有限制或其他什么,似乎不是我所读的内容。

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'Slides',
        array(
            'labels' => array(
                'name' => __( 'slides' ),
                'singular_name' => __( 'slide' )
            ),
            'public' => true,
            'has_archive' => true,
        )
    );

    register_post_type( 'Programs',
        array(
            'labels' => array(
                'name' => __( 'programs' ),
                'singular_name' => __( 'program' )
            ),
            'public' => true,
            'has_archive' => true,
        )
    );

    register_post_type( 'Boards',
        array(
            'labels' => array(
                'name' => __( 'Boards' ),
                'singular_name' => __( 'sponsor' )
            ),
            'public' => true,
            'has_archive' => true,
        )
    );

您的代码运行完美,您只是忘记了代码末尾的右括号 } 和 slug post 类型(小写)中的一些错误:

add_action( 'init', 'create_post_type' );
function create_post_type() {
  register_post_type( 'slides', // <== here to lowercase (slug)
    array(
      'labels' => array(
        'name' => __( 'Slides' ), // <== here 1st letter uppercase
        'singular_name' => __( 'Slide' ) // <== here 1st letter uppercase
      ),
      'public' => true,
      'has_archive' => true,
    )
  );

    register_post_type( 'programs', // <== here to lowercase (slug)
    array(
      'labels' => array(
        'name' => __( 'Programs' ), // <== here 1st letter uppercase
        'singular_name' => __( 'Program' ) // <== here 1st letter uppercase
      ),
      'public' => true,
      'has_archive' => true,
    )
  );

    register_post_type( 'boards', // <== here to lowercase (slug)
    array(
      'labels' => array(
        'name' => __( 'Boards' ), 
        'singular_name' => __( 'Board' )  // <== here singular
      ),
      'public' => true,
      'has_archive' => true,
    )
  );
} // <== forgetted this

我已经在测试网站上测试了您的代码,甚至您的自定义 post "Boards" 也在显示和工作:

You may need to flush the rewrite rules by going on backend permalinks settings and simply click on save to regenerate Wordpress rewrite rules related to this new post types…


WordPress 中 post 类型有限制吗?
不同自定义项的数量没有限制 posts。尝试下面的示例,该示例以非常紧凑的代码生成 10 个带有 for 循环的自定义 posts:

add_action( 'init', 'create_post_type' );
function create_post_type() {
    $arr = array('abcdef','bcdefg','cdefgh','defghi','efghij','fghijk','ghijkl','hijklm','ijklmn','jklmno');
    for( $i = 0; $i < 10; $i++ ) {
        $slug = $arr[$i]; 
        $slugs = $arr[$i].'s';
        register_post_type( $slug,
            array( 
                'labels' => array(
                    'name' => $slugs,
                    'singular_name' => $slug ),
                'public' => true,
                'has_archive' => true ) 
        );
    }
}

参考文献: