Custom Post Types / Taxonomies
When a site needs more than the news, add a custom post type. Define one post type per file in settings/post-types/; TOBIUO registers it. The case studies (settings/post-types/case.php) are the sample.
// settings/post-types/case.php
return [
'post_type' => 'case',
'args' => [
'label' => '事例紹介',
'public' => true,
'has_archive' => true,
'rewrite' => ['slug' => 'case', 'with_front' => false],
'supports' => ['title', 'editor', 'thumbnail', 'excerpt', 'revisions'],
'show_in_rest' => true,
],
'taxonomies' => [
'case_category' => [
'label' => '事例カテゴリー',
'hierarchical' => true,
'rewrite' => ['slug' => 'case/category', 'with_front' => false],
'seo' => ['description' => '事例紹介のカテゴリー別の一覧です。'],
],
],
'permalink' => ['structure' => '/%postname%/'],
'seo' => ['title' => '事例紹介', 'description' => '事例紹介の一覧です。'],
];
argsis passed toregister_post_type().taxonomiesmaps each taxonomy name to the arguments forregister_taxonomy().- Its
seoapplies to every term of the taxonomy and is not passed toregister_taxonomy(). Leave outtitle; each term's name is its title.
- Its
permalinkis the post URL structure. Without it, the post type keeps WordPress's default URLs (/case/test-case-1/).seoholds the archive's SEO settings. See SEO.- Keep
'with_front' => falsein everyrewrite; otherwise/news/is put in front of the URLs.
After adding or changing a definition, open Settings → Permalinks once to regenerate the rewrite rules. Tools → Content Structure (TOBIUO) shows a warning while rules are missing.
Permalinks
// /case/test-case-1/
'permalink' => ['structure' => '/%postname%/'],
// /case/sample/test-case-1/ (includes the category)
'permalink' => ['structure' => '/%case_category%/%postname%/'],
// /case/2026/10/test-case-1/ (includes the date, with date archives at /case/2026/10/)
'permalink' => ['structure' => '/%year%/%monthnum%/%postname%/', 'dateArchive' => true],
structuremust contain%postname%or%post_id%. It also accepts the date tags,%author%and the taxonomies of the same post type (%case_category%).dateArchiveandauthorArchiveadd/case/2026/10/and/case/author/name/. Link to them withtobiuo_get_year_link(),tobiuo_get_month_link(),tobiuo_get_day_link()andtobiuo_get_author_link().- A URL with the wrong category (
/case/other/test-case-1/) is redirected to the right one with a 301.
See the TOBIUO documentation for the details.
Category URLs
The usual shape puts the post type slug in front of the taxonomy slug.
// /case/category/sample/
'rewrite' => ['slug' => 'case/category', 'with_front' => false],
// /case-category/sample/ (without the post type slug)
'rewrite' => ['slug' => 'case-category', 'with_front' => false],
warning
Don't create a post or term whose slug is the last part of the taxonomy slug (category in this example). Their URLs would overlap.
Templates
| Page | Template |
|---|---|
| Archive | archive-{post type}.php |
| Post | single-{post type}.php |
| Taxonomy archive | taxonomy-{taxonomy}.php |
When the post type archive and the taxonomy archive share a layout, load one from the other.
// taxonomy-case_category.php
<?php
get_template_part('archive', 'case');
// archive-case.php
<?php
get_header();
// The term being shown, or null on the post type archive
$current_term = is_tax('case_category') ? get_queried_object() : null;
while (have_posts()) : the_post();
// Every case study, or only those in $current_term
endwhile;