Display Categories of A Custom Post

Quick Summary

  • The built-in category functions, such as the_category() and get_the_category(), return nothing for custom post types with their own taxonomy.
  • Use the_terms() to print linked terms, get_the_term_list() to return that HTML, or get_the_terms() to build your own markup.
  • Pass the post ID and your taxonomy slug, which appears after taxonomy= in the URL of the taxonomy's admin screen.

The WordPress category functions, such as the_category() and get_the_category(), only read the built-in category taxonomy. Custom post types usually get their own taxonomy instead, for example product_cat for WooCommerce products or a taxonomy you registered yourself, so those functions return nothing for them.

Use the term functions instead

To show the categories of a custom post, use the functions that take a taxonomy name:

  • the_terms() prints the post’s terms as links to their archives. Pass the post ID and the taxonomy slug, and optionally text to print before the list, a separator such as a comma, and text after it.
  • get_the_term_list() takes the same arguments but returns the HTML instead of printing it.
  • get_the_terms() returns the term objects themselves, so you can build your own markup from each term’s name and a URL from get_term_link().

Use them in the single template of your post type, such as single-{post_type}.php, or inside an archive loop, and pass the taxonomy slug your post type uses. You can find that slug in the taxonomy= part of the URL when you open the taxonomy’s screen in the admin.

If your custom post type was registered with the built-in category taxonomy, the_category() works for it as usual.

Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More