Bird
Raised Fist0
Wordpressframework~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of registering a custom post type in WordPress?
easy
A. To create a new type of content different from posts and pages
B. To change the WordPress theme
C. To add a new user role
D. To install a plugin automatically

Solution

  1. Step 1: Understand WordPress content types

    WordPress has default content types like posts and pages, but custom post types allow adding new content types.
  2. Step 2: Purpose of custom post types

    Registering a custom post type lets you organize and display content that doesn't fit posts or pages.
  3. Final Answer:

    To create a new type of content different from posts and pages -> Option A
  4. Quick Check:

    Custom post types = new content types [OK]
Hint: Custom post types add new content types beyond posts/pages [OK]
Common Mistakes:
  • Confusing custom post types with themes or plugins
  • Thinking it changes user roles
  • Assuming it installs plugins automatically
2. Which of the following is the correct way to hook the register_post_type function in WordPress?
easy
A. add_action('init', 'register_post_type')
B. add_action('wp_head', 'register_post_type')
C. add_filter('init', 'register_post_type')
D. add_action('admin_menu', 'register_post_type')

Solution

  1. Step 1: Identify the correct hook for registering post types

    The init hook is the standard place to register custom post types in WordPress.
  2. Step 2: Use add_action with 'init'

    Using add_action('init', 'register_post_type') correctly hooks the function to run at initialization.
  3. Final Answer:

    add_action('init', 'register_post_type') -> Option A
  4. Quick Check:

    Hook register_post_type on init [OK]
Hint: Use 'init' hook with add_action for registering post types [OK]
Common Mistakes:
  • Using add_filter instead of add_action
  • Hooking into 'wp_head' or 'admin_menu' incorrectly
  • Calling register_post_type directly without a hook
3. What will be the effect of this code snippet?
add_action('init', function() {
  register_post_type('book', [
    'label' => 'Books',
    'public' => true,
    'supports' => ['title', 'editor']
  ]);
});
medium
A. Causes a syntax error due to missing semicolons
B. Creates a private post type called 'book' without editor support
C. Creates a new public post type called 'book' with title and editor support
D. Registers a taxonomy instead of a post type

Solution

  1. Step 1: Analyze the register_post_type parameters

    The code registers a post type named 'book' with label 'Books', public visibility, and supports title and editor features.
  2. Step 2: Understand the effect of 'public' and 'supports'

    Setting 'public' to true makes it visible on the site, and 'supports' enables editing title and content.
  3. Final Answer:

    Creates a new public post type called 'book' with title and editor support -> Option C
  4. Quick Check:

    register_post_type with public true and supports = A [OK]
Hint: Check 'public' and 'supports' keys for post type behavior [OK]
Common Mistakes:
  • Confusing post type with taxonomy
  • Assuming missing semicolons cause errors in PHP arrays
  • Thinking 'public' false means visible
4. Identify the error in this custom post type registration code:
function create_movie_post_type() {
  register_post_type('movie', [
    'label' => 'Movies',
    'public' => true,
    'supports' => 'title,editor'
  ]);
}
add_action('init', 'create_movie_post_type');
medium
A. The hook 'init' is incorrect for registering post types
B. Missing a closing parenthesis in register_post_type
C. The function name cannot contain underscores
D. 'supports' should be an array, not a string

Solution

  1. Step 1: Check the 'supports' argument type

    The 'supports' argument must be an array of features, but here it is a string with comma-separated values.
  2. Step 2: Correct the 'supports' argument

    It should be ['title', 'editor'] instead of 'title,editor' to work properly.
  3. Final Answer:

    'supports' should be an array, not a string -> Option D
  4. Quick Check:

    'supports' requires array format [OK]
Hint: Use array for 'supports', not comma string [OK]
Common Mistakes:
  • Passing 'supports' as a string instead of array
  • Using wrong hook instead of 'init'
  • Incorrect function naming conventions
5. You want to register a custom post type 'event' that is public, supports title, editor, and custom fields, and has a custom menu icon. Which code snippet correctly achieves this?
hard
A. register_post_type('event', ['public' => false, 'supports' => ['title', 'editor'], 'menu_icon' => 'calendar']);
B. register_post_type('event', ['public' => true, 'supports' => ['title', 'editor', 'custom-fields'], 'menu_icon' => 'dashicons-calendar']);
C. register_post_type('event', ['public' => true, 'supports' => 'title,editor,custom-fields', 'menu_icon' => 'dashicons-calendar']);
D. register_post_type('event', ['public' => true, 'supports' => ['title', 'editor'], 'menu_icon' => 'dashicons-event']);

Solution

  1. Step 1: Check 'public' and 'supports' keys

    The post type must be public and support title, editor, and custom fields, so 'public' => true and 'supports' => ['title', 'editor', 'custom-fields'] are correct.
  2. Step 2: Verify 'menu_icon' value

    The icon must be a valid Dashicons class like 'dashicons-calendar'. register_post_type('event', ['public' => true, 'supports' => ['title', 'editor', 'custom-fields'], 'menu_icon' => 'dashicons-calendar']); uses this correctly.
  3. Step 3: Identify errors in other options

    register_post_type('event', ['public' => false, 'supports' => ['title', 'editor'], 'menu_icon' => 'calendar']); sets 'public' false and wrong icon string; register_post_type('event', ['public' => true, 'supports' => 'title,editor,custom-fields', 'menu_icon' => 'dashicons-calendar']); uses string for 'supports'; register_post_type('event', ['public' => true, 'supports' => ['title', 'editor'], 'menu_icon' => 'dashicons-event']); misses 'custom-fields' support.
  4. Final Answer:

    register_post_type('event', ['public' => true, 'supports' => ['title', 'editor', 'custom-fields'], 'menu_icon' => 'dashicons-calendar']); -> Option B
  5. Quick Check:

    Correct keys and values for event post type [OK]
Hint: Use array for supports and valid dashicons for menu_icon [OK]
Common Mistakes:
  • Using string instead of array for 'supports'
  • Setting 'public' to false by mistake
  • Using invalid icon names
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard