Challenge - 5 Problems
Custom Post Type Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this custom post type registration?
Consider the following WordPress code snippet that registers a custom post type. What will be the slug used in the URL for this post type?
Wordpress
<?php
function create_book_post_type() {
register_post_type('book', [
'labels' => [
'name' => __('Books'),
'singular_name' => __('Book')
],
'public' => true,
'has_archive' => true,
'rewrite' => ['slug' => 'library']
]);
}
add_action('init', 'create_book_post_type');
?>Attempts:
2 left
💡 Hint
Look at the 'rewrite' argument in the register_post_type function.
✗ Incorrect
The 'rewrite' argument with 'slug' => 'library' sets the URL slug to '/library/'. This overrides the default slug which would be the post type name 'book'.
❓ state_output
intermediate2:00remaining
What is the value of 'publicly_queryable' for this post type?
Given this registration code, what is the value of the 'publicly_queryable' property for the 'movie' post type?
Wordpress
<?php
function create_movie_post_type() {
register_post_type('movie', [
'public' => false,
'show_ui' => true
]);
}
add_action('init', 'create_movie_post_type');
?>Attempts:
2 left
💡 Hint
Check how 'public' affects 'publicly_queryable' by default.
✗ Incorrect
If 'public' is set to false, 'publicly_queryable' defaults to false unless explicitly set to true.
📝 Syntax
advanced2:00remaining
Which option will cause a syntax error when registering a custom post type?
Identify the option that contains a syntax error in the register_post_type call.
Attempts:
2 left
💡 Hint
Look carefully at the commas separating arguments.
✗ Incorrect
Option D is missing a comma between the first and second argument, causing a syntax error.
🔧 Debug
advanced2:00remaining
Why does this custom post type not appear in the admin menu?
This code registers a custom post type but it does not show up in the WordPress admin menu. What is the cause?
Wordpress
<?php
function create_album_post_type() {
register_post_type('album', [
'public' => false,
'show_ui' => false
]);
}
add_action('init', 'create_album_post_type');
?>Attempts:
2 left
💡 Hint
Check the 'show_ui' argument's effect on admin menu visibility.
✗ Incorrect
Setting 'show_ui' to false hides the post type from the admin menu even if registered.
🧠 Conceptual
expert2:00remaining
Which option best describes the effect of 'has_archive' => true in register_post_type?
What does setting 'has_archive' to true do for a custom post type in WordPress?
Attempts:
2 left
💡 Hint
Think about what an archive page means on a website.
✗ Incorrect
'has_archive' => true creates a URL where all posts of that type are listed, like a blog archive page.