0
0
Wordpressframework~10 mins

Registering custom post types in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to register a custom post type named 'book'.

Wordpress
<?php
function create_book_post_type() {
    register_post_type('book', [1]);
}
add_action('init', 'create_book_post_type');
Drag options to blanks, or click blank then click option'
Aarray('public' => true)
Barray('label' => 'Books')
Ctrue
D'public'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of an array as the second argument.
Forgetting to set the 'public' key to true.
2fill in blank
medium

Complete the code to add a label 'Books' to the custom post type.

Wordpress
<?php
function create_book_post_type() {
    register_post_type('book', array(
        'public' => true,
        'labels' => array(
            'name' => [1]
        )
    ));
}
add_action('init', 'create_book_post_type');
Drag options to blanks, or click blank then click option'
A'Book'
B'Books'
C'books'
D'BOOKS'
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular form 'Book' instead of plural.
Using lowercase or all uppercase which is less readable.
3fill in blank
hard

Fix the error in the code to make the custom post type support the editor feature.

Wordpress
<?php
function create_book_post_type() {
    register_post_type('book', array(
        'public' => true,
        'supports' => [1]
    ));
}
add_action('init', 'create_book_post_type');
Drag options to blanks, or click blank then click option'
A'editor'
Barray('edit')
Carray('editor')
D'supports'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of an array to 'supports'.
Using incorrect feature names like 'edit'.
4fill in blank
hard

Fill both blanks to register a custom post type 'movie' with public visibility and archive support.

Wordpress
<?php
function create_movie_post_type() {
    register_post_type('movie', array(
        'public' => [1],
        'has_archive' => [2]
    ));
}
add_action('init', 'create_movie_post_type');
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
C'true'
D'false'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings 'true' or 'false' instead of booleans.
Setting 'has_archive' to false when archive is needed.
5fill in blank
hard

Fill all three blanks to register a custom post type 'album' with label 'Albums', public visibility, and support for title and thumbnail.

Wordpress
<?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');
Drag options to blanks, or click blank then click option'
A'Albums'
Btrue
Carray('title', 'thumbnail')
D'Album'
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular label instead of plural.
Passing 'supports' as a string instead of an array.
Using string 'true' instead of boolean true.