php 注册多个自定义帖子类型CPT

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 注册多个自定义帖子类型CPT相关的知识,希望对你有一定的参考价值。

function register_post_types() {
    //this is where you can register custom post types
    function custom_posts($name, $single, $menu_order, $meta_cap, $capability_type, $supports, $taxonomies) {
      register_post_type( $name, array(
        'labels'                => array(
          'name'                  => _x( ucfirst($name), 'Post Type General Name', 'text_domain' ),
          'singular_name'         => _x( ucfirst($single), 'Post Type Singular Name', 'text_domain' ),
          'menu_name'             => __( ucfirst($name), 'text_domain' ),
          'name_admin_bar'        => __( ucfirst($name), 'text_domain' ),
        ),
        'description'           => __( 'Custom Post Type', 'text_domain' ),
        'capability_type'       => 'post',
        'menu_icon'             => 'dashicons-admin-post',
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,
        'publicly_queryable'    => true,
        'exclude_from_search'   => false,
        'menu_position'         => $menu_order,
        'map_meta_cap'          => $meta_cap,
        'capability_type'       => $capability_type,
        'supports'              => $supports,
        'taxonomies'            => $taxonomies,
      ) );
    }

    custom_posts('events', 'event', 20, true,
      array( 'custom_post','custom_posts' ),
      array( 'title', 'editor', 'excerpt', 'thumbnail', ),
      array( )
    );

    custom_posts('news', 'news', 21, true,
      array( 'custom_post','custom_posts' ),
      array( 'title', 'editor', 'excerpt', 'thumbnail', ),
      array( 'category' )
    );

    custom_posts('jobs', 'job', 22, true,
      array( 'job_post','job_posts' ),
      array( 'title', 'editor', ),
      array( )
    );

    custom_posts('directors', 'director', 23, true,
      array( 'custom_post','custom_posts' ),
      array( 'title', 'thumbnail', 'page-attributes' ),
      array( )
    );

    custom_posts('staff', 'member', 24, true,
      array( 'custom_post','custom_posts' ),
      array( 'title', 'thumbnail', ),
      array( )
    );
  }

以上是关于php 注册多个自定义帖子类型CPT的主要内容,如果未能解决你的问题,请参考以下文章

php 添加自定义帖子类型#cpt #cust

查询自定义帖子类型并按自定义帖子类型排序

php 在“前端布局”列表中显示“自定义帖子类型”。 Upfront隐藏'产品'CPT,因为它依赖于电子商务插件,此过滤器将显示CPT i

php 注册多个自定义帖子类型

php 注册多个自定义帖子类型

php CPT的自定义帖子状态