Kriuchko
1/8/2019 - 10:47 AM

Custom post type register

Wordpress register custom post type

\!h get post type title name
<?php echo get_post_type_object(get_post_type(get_the_ID()))->labels->name; ?>

\!h register post type

add_action('init', 'add_new_post_type');
function add_new_post_type()
{
  register_post_type(
    'destination',
    array(
      'labels' => array(
        'name' => __( 'Destinations', 'trlvr' ),
        'singular_name' => __( 'Destinations', 'trlvr' ),
        'add_new' => __( 'Add Destination', 'trlvr' ),
        'add_new_item' => __( 'Add New Destination', 'trlvr' ),
        'edit' => __( 'Edit Destinations', 'trlvr' ),
        'edit_item' => __( 'Edit Destination', 'trlvr' ),
        'edit_items' => __( 'Edit Destination', 'trlvr' ),
        'new_item' => __( 'New Destination', 'trlvr' ),
        'all_items' => __( 'All Destinations', 'trlvr' ),
        'view_items' => __( 'View Destinations', 'trlvr' ),
        'view_item' => __( 'View Destination', 'trlvr' ),
        'search_items' => __( 'Search Destination', 'trlvr' ),
        'not_found' =>  __( 'No Destinations found', 'trlvr' ),
        'not_found_in_trash' => __( 'No Destinations found in Trash', 'trlvr' ),
        'parent_item_colon' => '',
        'menu_name' => __( 'Destinations', 'trlvr' ),
        'name_admin_bar'=> __( 'Destination', 'trlvr' ),
        'parent' => __( 'Parent Destination', 'trlvr' ),
      ),
     'public' => true,
     'has_archive' => true,
     'show_ui' => true,
     'supports' => array('title', 'editor', 'custom-fields', 'thumbnail', 'excerpt', 'revisions'),
     'show_in_rest' => true,
    )
  );

  register_taxonomy(
    'quiz-topics',
    'quiz',
    array(
        'labels' => array(
            'name' => 'Topics',
            'add_new_item' => 'Add New Quiz Topic',
            'new_item_name' => "New Topic"
        ),
        'hierarchical' => true,
        'show_tagcloud' => false,
        'query_var' => true,
        'show_in_rest' => true,
    )
);
}

            
add_action('init', 'add_new_post_type');
function add_new_post_type(){
 register_post_type('news',
                   array(
                        'label' => 'News',
                        'description' => '',
                        'public' => true,
                        'show_ui' => true,
                        'show_in_menu' => true,
                        'capability_type' => 'post',
                        'hierarchical' => false,
                        'rewrite' => array('slug' => ''),
                        'query_var' => true,
                        'hierarchical' => true,
                        'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes'),
                        'labels' => array (
                                        'name' => 'News',
                                        'singular_name' => '',
                                        'menu_name' => 'News',
                                        'name_admin_bar'=> 'News',
                                        'add_new' => 'Add News',
                                        'add_new_item' => 'Add New News',
                                        'edit' => 'Edit',
                                        'edit_item' => 'Edit News',
                                        'new_item' => 'New News',
                                        'view' => 'View News',
                                        'view_item' => 'View News',
                                        'search_items' => 'Search News',
                                        'not_found' => 'No News Found',
                                        'not_found_in_trash' => 'No News Found in Trash',
                                        'parent' => 'Parent News',)
                        ) );
 register_taxonomy('newscategories', 'news', array('label' => 'News-Categories',
      'hierarchical' => true,
      'query_var' => true,
      'rewrite' => array('slug' => 'newscategories')));
}