Bird
Raised Fist0
Wordpressframework~10 mins

Custom post type arguments in Wordpress - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Custom post type arguments
Define args array
↓
Call register_post_type() with args
↓
WordPress registers CPT
↓
CPT appears in admin menu and frontend
↓
Use CPT in site content
You create an array of settings, pass it to register_post_type(), WordPress registers the new post type, and it becomes usable in admin and site.
Execution Sample
Wordpress
register_post_type('book', [
  'labels' => ['name' => 'Books'],
  'public' => true,
  'has_archive' => true
]);
This code registers a 'book' post type visible publicly with an archive page.
Execution Table
StepActionArguments StateResult
1Define args array{labels: {name: 'Books'}, public: true, has_archive: true}Args ready for registration
2Call register_post_type('book', args)Same as aboveWordPress registers 'book' CPT
3WordPress adds CPT to admin menuN/A'Books' menu appears in admin
4WordPress enables frontend archiveN/AArchive page for 'book' available
5Use CPT in siteN/ACan add/edit 'book' posts and display them
💡 All steps complete; CPT fully registered and usable
Variable Tracker
VariableStartAfter Step 1After Step 2Final
argsundefined{labels: {name: 'Books'}, public: true, has_archive: true}SameSame
post_type_registeredfalsefalsetruetrue
Key Moments - 3 Insights
Why do we need to pass an array of arguments to register_post_type?
The arguments tell WordPress how the new post type behaves and appears. Without them, WordPress wouldn't know if it should be public, have archives, or what label to show. See execution_table step 1 and 2.
What happens if 'public' is set to false in the arguments?
If 'public' is false, the post type won't show on the frontend or admin menus by default. This is why 'public' true in step 1 leads to visible admin menu in step 3.
Can we register multiple custom post types with different arguments?
Yes, each call to register_post_type with its own args registers a separate CPT. Each will appear separately in admin and frontend as per their args.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the state of 'post_type_registered' after step 2?
Aundefined
Btrue
Cfalse
Dnull
💡 Hint
Check variable_tracker row for 'post_type_registered' after Step 2
At which step does the 'Books' menu appear in the WordPress admin?
AStep 3
BStep 1
CStep 4
DStep 5
💡 Hint
See execution_table row describing admin menu addition
If we set 'public' to false in the args, which step's result would change?
AStep 3 - Admin menu appears
BStep 5 - Use CPT in site
CAll of the above
DStep 4 - Archive page available
💡 Hint
Refer to key_moments about 'public' argument effects
Concept Snapshot
register_post_type('name', args) registers a custom post type.
args is an array defining labels, visibility, archive, and features.
'public' true makes CPT visible in admin and frontend.
'labels' define menu and UI text.
Use CPT to organize content beyond posts/pages.
Full Transcript
To create a custom post type in WordPress, you define an array of arguments that describe how the post type behaves and looks. Then you call register_post_type with a unique name and these arguments. WordPress registers the post type, adds it to the admin menu if public, and enables frontend features like archives. The key argument 'public' controls visibility. This process lets you add new content types like 'Books' that behave like posts but are separate. The execution steps show defining args, calling register_post_type, WordPress registering the CPT, adding admin menu, enabling archive, and finally using the CPT in the site.

Practice

(1/5)
1. Which argument in register_post_type controls whether the custom post type appears in the WordPress admin menu?
easy
A. public
B. menu_position
C. supports
D. rewrite

Solution

  1. Step 1: Understand the role of menu_position

    The menu_position argument sets the location of the custom post type in the WordPress admin menu.
  2. Step 2: Compare with other arguments

    public controls visibility on front-end, supports defines features, rewrite controls URL structure.
  3. Final Answer:

    menu_position -> Option B
  4. Quick Check:

    Admin menu location = menu_position [OK]
Hint: Menu location is set by menu_position argument [OK]
Common Mistakes:
  • Confusing public with menu visibility
  • Thinking supports controls menu
  • Assuming rewrite affects admin menu
2. Which of the following is the correct way to set a custom post type to be publicly queryable in register_post_type arguments?
easy
A. "public_queryable" => true
B. "publiclyqueryable" => true
C. "public_queryable" => "true"
D. "publicly_queryable" => true

Solution

  1. Step 1: Recall the exact argument name

    The correct argument is publicly_queryable with an 'ly' and underscore.
  2. Step 2: Check value type and spelling

    The value must be boolean true, not string, and spelling must be exact.
  3. Final Answer:

    "publicly_queryable" => true -> Option D
  4. Quick Check:

    Correct spelling and boolean value = publicly_queryable true [OK]
Hint: Remember 'publicly_queryable' with 'ly' and boolean true [OK]
Common Mistakes:
  • Misspelling argument name
  • Using string "true" instead of boolean true
  • Omitting underscore
3. Given this code snippet, what will be the value of $args['has_archive'] after registration?
$args = [
  'public' => true,
  'has_archive' => false,
  'rewrite' => ['slug' => 'books']
];
register_post_type('book', $args);
medium
A. true
B. null
C. false
D. array with slug 'books'

Solution

  1. Step 1: Check the has_archive argument value

    It is explicitly set to false in the array.
  2. Step 2: Understand effect of rewrite on has_archive

    The rewrite argument does not override has_archive setting.
  3. Final Answer:

    false -> Option C
  4. Quick Check:

    Explicit has_archive false remains false [OK]
Hint: Explicit has_archive false stays false despite rewrite [OK]
Common Mistakes:
  • Assuming rewrite slug enables archive
  • Confusing has_archive with rewrite
  • Thinking default true overrides false
4. Identify the error in this register_post_type argument array:
$args = [
  'public' => 'yes',
  'supports' => 'title,editor',
  'menu_icon' => 'dashicons-book'
];
register_post_type('book', $args);
medium
A. 'supports' should be an array, not a comma-separated string
B. 'public' should be boolean true, not string 'yes'
C. 'menu_icon' value is invalid, should be a URL
D. No errors, code is correct

Solution

  1. Step 1: Check the supports argument type

    supports must be an array of features, not a string.
  2. Step 2: Verify other arguments

    public accepts boolean or string 'true'/'false', 'yes' is invalid but PHP may coerce; menu_icon accepts dashicons slug.
  3. Final Answer:

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

    Supports must be array, not string [OK]
Hint: Supports argument must be an array, not a string [OK]
Common Mistakes:
  • Passing supports as string instead of array
  • Using invalid string for public
  • Thinking menu_icon needs URL
5. You want to create a custom post type 'movie' that is public, supports title and editor, has an archive page at '/films', and appears below Posts in the admin menu. Which $args array is correct?
hard
A. { 'public' => true, 'supports' => ['title', 'editor'], 'has_archive' => true, 'rewrite' => ['slug' => 'films'], 'menu_position' => 5 }
B. { 'public' => true, 'supports' => ['title', 'editor'], 'has_archive' => 'films', 'rewrite' => true, 'menu_position' => 20 }
C. { 'public' => true, 'supports' => 'title,editor', 'has_archive' => true, 'rewrite' => ['slug' => 'movies'], 'menu_position' => 5 }
D. { 'public' => false, 'supports' => ['title', 'editor'], 'has_archive' => true, 'rewrite' => ['slug' => 'films'], 'menu_position' => 5 }

Solution

  1. Step 1: Check public visibility and supports

    { 'public' => true, 'supports' => ['title', 'editor'], 'has_archive' => true, 'rewrite' => ['slug' => 'films'], 'menu_position' => 5 } sets public to true and supports as an array with 'title' and 'editor', which is correct.
  2. Step 2: Verify archive and rewrite slug

    has_archive is true and rewrite slug is 'films' to get archive at '/films'.
  3. Step 3: Confirm menu position

    menu_position 5 places it below Posts in admin menu.
  4. Final Answer:

    Option A matches all requirements correctly -> Option A
  5. Quick Check:

    Public, supports array, archive slug, menu position 5 = { 'public' => true, 'supports' => ['title', 'editor'], 'has_archive' => true, 'rewrite' => ['slug' => 'films'], 'menu_position' => 5 } [OK]
Hint: Use array for supports, boolean for public, correct slug in rewrite [OK]
Common Mistakes:
  • Passing supports as string instead of array
  • Setting public false when it should be true
  • Incorrect has_archive or rewrite values
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