Custom post type arguments tell WordPress how to create and show your new content type. They control what features it has and how it behaves.
Custom post type arguments in Wordpress
register_post_type('post_type_name', [ 'labels' => [ 'name' => 'Plural Name', 'singular_name' => 'Singular Name' ], 'public' => true, 'has_archive' => true, 'supports' => ['title', 'editor', 'thumbnail'], 'menu_icon' => 'dashicons-admin-post' ]);
The first argument is the unique name for your post type (lowercase, no spaces).
The second argument is an array of options that control how the post type works and looks.
register_post_type('book', [ 'labels' => [ 'name' => 'Books', 'singular_name' => 'Book' ], 'public' => true, 'has_archive' => true ]);
register_post_type('movie', [ 'labels' => [ 'name' => 'Movies', 'singular_name' => 'Movie' ], 'public' => false, 'show_ui' => true, 'supports' => ['title', 'editor'] ]);
register_post_type('recipe', [ 'labels' => [ 'name' => 'Recipes', 'singular_name' => 'Recipe' ], 'public' => true, 'menu_icon' => 'dashicons-carrot', 'supports' => ['title', 'editor', 'thumbnail', 'comments'] ]);
This code creates a new post type called 'event' that is public, has archive pages, supports title, editor, and thumbnail, and uses a calendar icon in the admin menu.
<?php
function create_custom_post_type() {
register_post_type('event', [
'labels' => [
'name' => 'Events',
'singular_name' => 'Event'
],
'public' => true,
'has_archive' => true,
'supports' => ['title', 'editor', 'thumbnail'],
'menu_icon' => 'dashicons-calendar-alt'
]);
}
add_action('init', 'create_custom_post_type');Always hook your custom post type registration to the 'init' action to ensure WordPress is ready.
Use descriptive labels to make the admin area user-friendly.
Setting 'public' to false hides the post type from the front end but can still show it in admin if 'show_ui' is true.
Custom post type arguments define how your new content type behaves and looks.
Use the 'labels', 'public', 'supports', and 'menu_icon' keys to customize your post type.
Register your post type inside a function hooked to 'init' for proper loading.
Practice
register_post_type controls whether the custom post type appears in the WordPress admin menu?Solution
Step 1: Understand the role of
Themenu_positionmenu_positionargument sets the location of the custom post type in the WordPress admin menu.Step 2: Compare with other arguments
publiccontrols visibility on front-end,supportsdefines features,rewritecontrols URL structure.Final Answer:
menu_position -> Option BQuick Check:
Admin menu location = menu_position [OK]
- Confusing public with menu visibility
- Thinking supports controls menu
- Assuming rewrite affects admin menu
register_post_type arguments?Solution
Step 1: Recall the exact argument name
The correct argument ispublicly_queryablewith an 'ly' and underscore.Step 2: Check value type and spelling
The value must be booleantrue, not string, and spelling must be exact.Final Answer:
"publicly_queryable" => true -> Option DQuick Check:
Correct spelling and boolean value = publicly_queryable true [OK]
- Misspelling argument name
- Using string "true" instead of boolean true
- Omitting underscore
$args['has_archive'] after registration?$args = [
'public' => true,
'has_archive' => false,
'rewrite' => ['slug' => 'books']
];
register_post_type('book', $args);Solution
Step 1: Check the
It is explicitly set tohas_archiveargument valuefalsein the array.Step 2: Understand effect of
Therewriteonhas_archiverewriteargument does not overridehas_archivesetting.Final Answer:
false -> Option CQuick Check:
Explicit has_archive false remains false [OK]
- Assuming rewrite slug enables archive
- Confusing has_archive with rewrite
- Thinking default true overrides false
register_post_type argument array:$args = [
'public' => 'yes',
'supports' => 'title,editor',
'menu_icon' => 'dashicons-book'
];
register_post_type('book', $args);Solution
Step 1: Check the
supportsargument typesupportsmust be an array of features, not a string.Step 2: Verify other arguments
publicaccepts boolean or string 'true'/'false', 'yes' is invalid but PHP may coerce;menu_iconaccepts dashicons slug.Final Answer:
'supports' should be an array, not a comma-separated string -> Option AQuick Check:
Supports must be array, not string [OK]
- Passing supports as string instead of array
- Using invalid string for public
- Thinking menu_icon needs URL
$args array is correct?Solution
Step 1: Check public visibility and supports
{ 'public' => true, 'supports' => ['title', 'editor'], 'has_archive' => true, 'rewrite' => ['slug' => 'films'], 'menu_position' => 5 } setspublicto true andsupportsas an array with 'title' and 'editor', which is correct.Step 2: Verify archive and rewrite slug
has_archiveis true andrewriteslug is 'films' to get archive at '/films'.Step 3: Confirm menu position
menu_position5 places it below Posts in admin menu.Final Answer:
Option A matches all requirements correctly -> Option AQuick Check:
Public, supports array, archive slug, menu position 5 = { 'public' => true, 'supports' => ['title', 'editor'], 'has_archive' => true, 'rewrite' => ['slug' => 'films'], 'menu_position' => 5 } [OK]
- Passing supports as string instead of array
- Setting public false when it should be true
- Incorrect has_archive or rewrite values
Ready to prove it?
Pass the test and this pattern moves unknown
