IntermediateLesson 17 of 305 min read

Custom post types and taxonomies

Create your own content types such as Projects, with their own addresses and groupings, using plugin or code, and show them on the site, with a real test.

In this lesson you will

  • Know when to use a custom post type
  • Add taxonomies
  • Register types safely in a plugin
  • Display custom content

About 16 minutes

When a post is the wrong shape

Selim is a photographer who keeps adding ‘projects’ to his blog. They get mixed with news posts, show up in the wrong feeds and have no place for a client name or a date. His site needs a separate home for projects. WordPress calls these separate content types custom post types. Posts and pages are two built-in types, and you can add more, such as Projects, Recipes, Events or Team Members, each with its own menu, address and layout.

Why use one

  • Keeps different content apart in the dashboard.
  • Gives each type its own address, like /projects/.
  • Lets you choose the editor features: title, text, featured image.
  • Allows archive pages and custom layouts per type.
  • Makes querying easier: show only projects here.

Custom taxonomies

A taxonomy is a way to group content. Posts use Categories and Tags. A custom taxonomy, such as ‘Skills’ for projects, is a new set of labels. It can be hierarchical like categories or flat like tags. Use a taxonomy when you want to browse or filter by that label.

A real example

A test registered a ‘projects’ type and a flat ‘skills’ taxonomy, created three projects tagged with skills, queried them and then removed everything. The output is real:

projects stored: 3
projects tagged WordPress: 2 -> Zz Club app, Zz Bakery site
type 'post' count unaffected: yes
archive URL pattern: /projects/
single URL pattern: /projects/zz-bakery-site/
cleaned: yes

Look at the results. Three projects were stored apart from posts. A filter found the two tagged WordPress. The archive lives at /projects/ and each project at /projects/name/. Because the type was registered only while the script ran, nothing remained afterwards; on a real site the registration code lives in a plugin or theme so it is always present.

How to create one

There are two practical ways. First, use a well-maintained plugin that provides a screen for building post types and taxonomies, no code needed. Second, register them in code. Code belongs in a small plugin of your own, not in the theme, because a theme change would otherwise hide your content. A site-specific plugin keeps content types alive whatever theme is active.

register_post_type('project', [
  'label' => 'Projects',
  'public' => true,
  'has_archive' => true,
  'rewrite' => ['slug' => 'projects'],
  'supports' => ['title', 'editor', 'thumbnail'],
  'show_in_rest' => true,
]);

The last setting makes the type available to the block editor and to the REST interface. After adding a new type, visit Settings, Permalinks and click Save once so WordPress refreshes its address rules.

Showing the content

  • Use your theme’s archive template for /projects/.
  • In a block theme, edit the templates in the Site Editor.
  • Use a Query Loop block to list projects anywhere, filtered by type or skill.
  • Add the type to your menu so visitors can find it.

Naming tips

  • Use singular and plural labels that make sense to editors.
  • Keep the slug short, lowercase and unlikely to clash with a page.
  • Plan the type before using it, because changing it later affects addresses.

Practice

Choose a kind of content you have on your practice site that does not belong in posts. Write down its fields, grouping labels and address. Create the type with a plugin, add three items, add a menu link and check the archive page.

Practice answer

If the archive page shows an error, save Settings, Permalinks once. If the items appear in the wrong layout, edit the archive template for that type.

Common mistake

Putting post-type code in the theme. When you change theme, the content seems to vanish. Keep it in a small plugin.

Planning fields and groupings together

Before you register a type, list what each item needs. A project might need a title, a description, a picture, a client name and a date. Which of these should visitors be able to filter by? Those are candidates for taxonomies, such as skills or year. Which are only shown? Those are candidates for fields, which the next lesson covers. Keeping this difference clear avoids a messy site.

Need Use
Browse or filter by it Taxonomy
Show only on the item Custom field
Main text and pictures Editor and featured image

A short checklist for a new content type

  • Choose a clear singular and plural name.
  • Choose a short address slug.
  • Decide which taxonomies it needs.
  • Make an archive and a single template.
  • Add it to the menu and the sitemap.

Planning on paper takes ten minutes and saves hours of rework, because changing slugs after launch means redirects and lost search visibility.

Common problems and quick fixes

  • The archive shows a 404 error: save Settings, Permalinks once.
  • Items appear in the blog feed: check the type’s settings and your Query Loop.
  • The content vanished after a theme change: the registration code was in the old theme, so move it to a plugin.
  • The editor looks old-fashioned: set the show-in-REST option so the block editor loads.
  • The address clashes with a page: choose a different slug.

Keep a note of each type you create, with its slug and fields, so another person can understand the site later.

Check what you learned

Five quick questions. Pick an answer and you will see straight away whether it is right and why.

What is a custom post type?

  1. A new theme
  2. A user role
  3. A new type of content besides posts and pages
  4. A backup

Such as Projects or Recipes.

What is a taxonomy?

  1. A way to group content
  2. A password
  3. A picture size
  4. A font

Categories and tags are taxonomies.

Where should post-type code live?

  1. In the theme only
  2. In the media library
  3. In a small plugin
  4. In a comment

A theme change should not hide content.

What should you do after adding a new type?

  1. Save Settings, Permalinks once
  2. Delete the plugin
  3. Rename the site
  4. Clear comments

It refreshes the address rules.

In the real test, where did the archive live?

  1. /admin/
  2. /projects/
  3. /shop/
  4. /login/

Each item lived under /projects/name/.

Summary

  • Custom post types give content its own home.
  • Taxonomies group items for browsing.
  • Keep registration code in a plugin.
  • Save Permalinks after adding a type.

Next lesson

Next: custom fields, for extra details on each item.

Questions

Do I need code for a custom post type?

No. Plugins give you screens for creating them. Code is optional.

Can I turn existing posts into a custom type?

Yes, with a plugin or a careful database change. Take a backup first.

Will custom types work with any theme?

They are stored in WordPress, but how they look depends on the theme's templates.

Progress is saved in this browser.