0
0
Wordpressframework~30 mins

Custom post type arguments in Wordpress - Mini Project: Build & Apply

Choose your learning style9 modes available
Custom Post Type Arguments in WordPress
📖 Scenario: You are building a WordPress website for a local art gallery. You want to create a new content type to manage the artworks separately from regular posts.
🎯 Goal: Create a custom post type called artwork with specific arguments to control its behavior and appearance in the WordPress admin and on the site.
📋 What You'll Learn
Create a function called register_artwork_post_type
Use register_post_type to register a post type named artwork
Set the labels argument with name as 'Artworks' and singular_name as 'Artwork'
Set public to true
Set has_archive to true
Set show_in_rest to true to enable Gutenberg editor support
Hook the function to init action
💡 Why This Matters
🌍 Real World
Custom post types let you organize different kinds of content separately, like artworks, events, or products, making your site easier to manage and more user-friendly.
💼 Career
Knowing how to register and configure custom post types is essential for WordPress developers building custom websites or plugins.
Progress0 / 4 steps
1
Create the function and basic post type registration
Create a function called register_artwork_post_type and inside it call register_post_type with the post type name 'artwork' and an empty array for arguments.
Wordpress
Need a hint?

Start by defining the function and call register_post_type with the post type name and empty arguments.

2
Add labels and basic arguments
Inside the register_artwork_post_type function, add an array called $args with a labels key. Set labels to an array with 'name' as 'Artworks' and 'singular_name' as 'Artwork'. Also set public to true and has_archive to true. Pass $args as the second argument to register_post_type.
Wordpress
Need a hint?

Use an array for $args with the required keys and pass it to register_post_type.

3
Enable Gutenberg editor support
Add the show_in_rest argument to the $args array and set it to true to enable the Gutenberg editor for the artwork post type.
Wordpress
Need a hint?

Add 'show_in_rest' => true inside the $args array.

4
Hook the function to the init action
Add a line after the register_artwork_post_type function to hook it to the init action using add_action with the function name 'register_artwork_post_type'.
Wordpress
Need a hint?

Use add_action with 'init' and the function name 'register_artwork_post_type'.