Skip to content

Post Type Fields

The Post_Type_Fields class registers ACF field groups and attaches them to specific post types, page templates, or taxonomy term edit screens. Fields are composed with ACF_Builder islands, and show_when is automatically resolved.

This is used when you need custom fields on the edit screen of a post type (not inside Flexible Content modules).


  • Island-composed fields: Uses ACF_Builder for field definitions
  • Multiple location types: Attach to post types, page templates, or taxonomy term screens
  • Combined conditions: Support for post_taxonomy conditions (e.g., show fields only for a specific term)
  • Deterministic keys: Safe for environment migrations
  • show_when support: Conditional visibility between fields

functions/project/config/post-type-fields_config.php

<?php
return [
[
'title' => 'Resource Details',
'post_type' => 'resource',
'fields' => array_merge(
ACF_Builder::image(['name' => 'hero_image', 'label' => 'Hero Image']),
ACF_Builder::text(['name' => 'hero_subtitle', 'label' => 'Hero Subtitle']),
ACF_Builder::boolean(['name' => 'is_gated', 'label' => 'Is Gated Content?']),
ACF_Builder::url([
'name' => 'gate_url',
'label' => 'Gate URL',
'show_when' => ['is_gated', '==', '1'],
]),
),
],
[
'title' => 'Team Member Details',
'post_type' => 'team',
'fields' => array_merge(
ACF_Builder::title(['name' => 'position', 'label' => 'Position/Role']),
ACF_Builder::url(['name' => 'linkedin', 'label' => 'LinkedIn URL']),
ACF_Builder::image(['name' => 'headshot', 'label' => 'Headshot']),
),
],
];

Each group in the array accepts:

ParameterTypeDescription
titlestringField group title (shown in the admin)
post_typestring or arrayPost type(s) to attach to
page_templatestring or arrayPage template(s) to attach to
taxonomystring or arrayTaxonomy term edit screen(s)
post_taxonomystring or arrayTaxonomy condition (e.g., 'type:case-study')
fieldsarrayFields composed with ACF_Builder

<?php
[
'title' => 'Industry Info',
'post_type' => 'industry',
'fields' => array_merge(
ACF_Builder::image(['name' => 'icon', 'label' => 'Industry Icon']),
ACF_Builder::wysiwyg(['name' => 'overview', 'label' => 'Overview']),
),
],

<?php
[
'title' => 'SEO Fields',
'post_type' => ['resource', 'blog', 'industry'],
'fields' => array_merge(
ACF_Builder::text(['name' => 'seo_title', 'label' => 'SEO Title']),
ACF_Builder::text(['name' => 'seo_description', 'label' => 'SEO Description', 'rows' => 2]),
),
],

<?php
[
'title' => 'Homepage Fields',
'page_template' => 'page-home.php',
'fields' => array_merge(
ACF_Builder::title(['name' => 'hero_heading']),
ACF_Builder::text(['name' => 'hero_description']),
),
],

Show fields when editing a taxonomy term (e.g., category edit page):

<?php
[
'title' => 'Category Settings',
'taxonomy' => 'resources_categories',
'fields' => array_merge(
ACF_Builder::image(['name' => 'category_icon', 'label' => 'Icon']),
ACF_Builder::text(['name' => 'category_description', 'label' => 'Short Description']),
),
],

Show fields only when a post has a specific taxonomy term assigned:

<?php
[
'title' => 'Case Study Fields',
'post_type' => 'resource',
'post_taxonomy' => 'resource_type:case-study',
'fields' => array_merge(
ACF_Builder::title(['name' => 'client_name', 'label' => 'Client Name']),
ACF_Builder::text(['name' => 'results', 'label' => 'Key Results']),
),
],

Knowledge Check

Test your understanding of this section

Loading questions...