A custom post type is a way to create content types other than the default posts and pages, like portfolios, testimonials, or products.
Click to reveal answer
beginner
Which WordPress function is used to register a custom post type?
The function register_post_type() is used to create a new custom post type.
Click to reveal answer
intermediate
What are the two main arguments passed to register_post_type()?
The first is the post type key (a string identifier), and the second is an array of options that define labels, visibility, and features.
Click to reveal answer
intermediate
Why should you hook register_post_type() into the init action?
Because WordPress loads custom post types during initialization, hooking into init ensures your post type is registered early and available everywhere.
Click to reveal answer
beginner
Name two common features you can enable for a custom post type.
You can enable features like title, editor, thumbnail, excerpt, and comments.
Click to reveal answer
Which hook is best to use when registering a custom post type?
Awp_footer
Bwp_head
Cadmin_menu
Dinit
✗ Incorrect
The init hook runs early and is the recommended place to register custom post types.
What does the first argument of register_post_type() represent?
AThe post content
BThe post title
CThe post type key (identifier)
DThe post author
✗ Incorrect
The first argument is a string that identifies the custom post type.
Which feature allows a custom post type to have a featured image?
Acomments
Bthumbnail
Cexcerpt
Dauthor
✗ Incorrect
The thumbnail feature enables featured images for the post type.
What is the purpose of the 'labels' array in register_post_type()?
ATo define the text shown in the admin UI for the post type
BTo set the post content
CTo control the post's visibility on the site
DTo assign categories
✗ Incorrect
The 'labels' array customizes the names and messages shown in the WordPress admin for the post type.
If you want your custom post type to appear in the WordPress admin menu, which argument should you set?
Ashow_ui to true
Bpublic to false
Chas_archive to false
Dexclude_from_search to true
✗ Incorrect
Setting show_ui to true makes the post type visible in the admin menu.
Explain how to register a custom post type in WordPress and why it is useful.
Think about how WordPress organizes content beyond posts and pages.
You got /5 concepts.
Describe the role of the 'supports' argument when registering a custom post type.
It controls what editing tools the post type has.
You got /3 concepts.
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
Step 1: Understand WordPress content types
WordPress has default content types like posts and pages, but custom post types allow adding new content types.
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.
Final Answer:
To create a new type of content different from posts and pages -> Option A
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
Step 1: Identify the correct hook for registering post types
The init hook is the standard place to register custom post types in WordPress.
Step 2: Use add_action with 'init'
Using add_action('init', 'register_post_type') correctly hooks the function to run at initialization.
Final Answer:
add_action('init', 'register_post_type') -> Option A
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
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
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.
Step 2: Correct the 'supports' argument
It should be ['title', 'editor'] instead of 'title,editor' to work properly.
Final Answer:
'supports' should be an array, not a string -> Option D
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?
The post type must be public and support title, editor, and custom fields, so 'public' => true and 'supports' => ['title', 'editor', 'custom-fields'] are correct.
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.