0
0
Wordpressframework~20 mins

Registering custom post types in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Custom Post Type Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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');
?>
AThe URL slug will be '/library/'
BThe URL slug will be '/book/'
CThe URL slug will be '/books/'
DThe URL slug will be '/archive/'
Attempts:
2 left
💡 Hint
Look at the 'rewrite' argument in the register_post_type function.
state_output
intermediate
2: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');
?>
Atrue
Bfalse
Cnull
Dundefined
Attempts:
2 left
💡 Hint
Check how 'public' affects 'publicly_queryable' by default.
📝 Syntax
advanced
2: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.
Aregister_post_type('event', ['public' => true, 'labels' => ['name' => 'Events']]);
Bregister_post_type('event', ['public' => true, 'labels' => ['name' => 'Events']])
C;)]]'stnevE' >= 'eman'[ >= 'slebal' ,eurt >= 'cilbup'[ ,'tneve'(epyt_tsop_retsiger
Dregister_post_type('event' ['public' => true, 'labels' => ['name' => 'Events']]);
Attempts:
2 left
💡 Hint
Look carefully at the commas separating arguments.
🔧 Debug
advanced
2: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');
?>
AMissing 'menu_position' causes it to not appear in admin menu.
B'public' is false, so the post type cannot be registered.
C'show_ui' is set to false, so the admin menu link is hidden.
DThe 'init' hook is incorrect for registering post types.
Attempts:
2 left
💡 Hint
Check the 'show_ui' argument's effect on admin menu visibility.
🧠 Conceptual
expert
2: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?
AEnables an archive page listing all posts of this type accessible via a URL.
BAutomatically creates a new database table for the post type.
CRegisters the post type only for admin users.
DMakes the post type publicly queryable but disables single post views.
Attempts:
2 left
💡 Hint
Think about what an archive page means on a website.