register_post_type in WordPress

register_post_type in WordPress

register_post_type(‘posttype-id’,[
        ‘public’ => true,
        ‘labels’ => [
            ‘name’  =>  ‘Posts’,
            ‘all_items’ => ‘All Posts’,
            ‘add_new’ => ‘Add New’,
            ‘add_new_item’ => ‘Add New Post’,
            ‘set_featured_image’ => ‘Set Featured Image’,
            ‘featured_image’ => ‘Featured Image’,
        ],
        ‘supports’ => [‘title’,’thumbnail’,’editor’,’post-formats’],
        ‘menu_position’ => 20,
        ‘menu_icon’ => ‘dashicons-format-image’,
    ]);
register_post_type('posttype-id',[
        'public' => true,
        'labels' => [
            'name'  =>  'Posts',
            'all_items' => 'All Posts',
            'add_new' => 'Add New',
            'add_new_item' => 'Add New Post',
            'set_featured_image' => 'Set Featured Image',
            'featured_image' => 'Featured Image',
        ],
        'supports' => ['title','thumbnail','editor','post-formats','page-attributes','custom-fields']
'],
        'menu_position' => 20,
        'menu_icon' => 'dashicons-format-image',
    ]);

//Another way

register_post_type('book',array(
    'public' => true,
    'labels' => array(
        'name' => 'Books',
    ),
));

call it

?php 
    
     $book = new WP_Query(array(
         'post_type' => 'book',
     ));
     
     while($book->have_posts()): $book->the_post();

    ?>
    <h2><?php 
    
    the_title();
    
    ?></h2>
    <?php 
    
    endwhile;
    
    ?>