Complete the code to register a custom post type named 'book'.
<?php
function create_book_post_type() {
register_post_type('book', [1]);
}
add_action('init', 'create_book_post_type');The register_post_type function requires an array of arguments as the second parameter to define the post type's behavior. Using array('public' => true) makes the post type publicly accessible.
Complete the code to add a label 'Books' to the custom post type.
<?php
function create_book_post_type() {
register_post_type('book', array(
'public' => true,
'labels' => array(
'name' => [1]
)
));
}
add_action('init', 'create_book_post_type');The 'name' label should be the plural form of the post type, so 'Books' is correct.
Fix the error in the code to make the custom post type support the editor feature.
<?php
function create_book_post_type() {
register_post_type('book', array(
'public' => true,
'supports' => [1]
));
}
add_action('init', 'create_book_post_type');The 'supports' argument expects an array of features. To enable the editor, use array('editor').
Fill both blanks to register a custom post type 'movie' with public visibility and archive support.
<?php
function create_movie_post_type() {
register_post_type('movie', array(
'public' => [1],
'has_archive' => [2]
));
}
add_action('init', 'create_movie_post_type');Both 'public' and 'has_archive' should be set to the boolean true (without quotes) to enable public visibility and archive pages.
Fill all three blanks to register a custom post type 'album' with label 'Albums', public visibility, and support for title and thumbnail.
<?php
function create_album_post_type() {
register_post_type('album', array(
'labels' => array('name' => [1]),
'public' => [2],
'supports' => [3]
));
}
add_action('init', 'create_album_post_type');Use 'Albums' as the plural label, set 'public' to boolean true, and 'supports' to an array with 'title' and 'thumbnail' to enable those features.