Jump to Navigation Jump to Main Content Jump to Footer
Home » Docs » Features » Automated Custom Post Type and ACF Options Pages registration

Automated Custom Post Type and ACF Options Pages registration

Define content once and let the theme do the rest. Custom Post Types and ACF Options Pages are registered automatically based on simple, convention‑driven configuration—no boilerplate or repetitive hooks. Editors get purpose‑built post types and centralized settings pages out of the box, while developers keep a clean codebase with predictable slugs, labels, capabilities, and fields. The result is faster setup, fewer mistakes, and a consistent editing experience that scales as your content model grows.

Overview

  • CPTs are declared via a filter and registered on init by Chisel\WP\CustomPostTypes (inc/WP/CustomPostTypes.php) using Chisel\Factory\RegisterCustomPostType (inc/Factory/RegisterCustomPostType.php).
  • Taxonomies are declared via a filter and registered on init by Chisel\WP\CustomTaxonomies (inc/WP/CustomTaxonomies.php) using Chisel\Factory\RegisterCustomTaxonomy (inc/Factory/RegisterCustomTaxonomy.php).
  • ACF Options Pages are declared in arrays, filterable, and registered on acf/init by Chisel\WP\Acf (inc/WP/Acf.php) using Chisel\Factory\RegisterAcfOptionsPage (inc/Factory/RegisterAcfOptionsPage.php).

Custom Post Types

  • Where: inc/WP/CustomPostTypes.phpregister_post_types()
    • Reads $this->post_typesset_post_types()apply_filters('chisel_custom_post_types', $post_types)
    • Applies defaults, then calls RegisterCustomPostType::register_post_type()
  • Defaults (set in after_setup_theme via set_properties()):
    • supports → filter chisel_default_post_type_supports (default: ['title','page-attributes','revisions','author'])
    • rewrite_args → filter chisel_default_post_type_rewrite_args (default slug empty; with_front, feeds, pages, ep_mask)
  • Registration (inc/Factory/RegisterCustomPostType.php):
    • Labels auto-generated; can override via labels args.
    • rewrite.slug defaults to the CPT name.
    • show_in_rest defaults to true (keeps block editor/REST enabled).
    • If supports contains thumbnail, CPT is added to filter chisel_post_thumbnails_post_types.
  • Additional supported args (opt-in if provided in your CPT array): rest_base, rest_namespace, rest_controller_class, autosave_rest_controller_class, revisions_rest_controller_class, late_route_registration, map_meta_cap, register_meta_box_cb, taxonomies, template, template_lock

Add a CPT (example)

private function set_post_types() {
		$this->post_types = array(
			'book' => array(
				'singular'   => __('Book', 'chisel'),
		    'plural'     => __('Books', 'chisel'),
		    'supports'   => array( 'editor','thumbnail','excerpt' ), // merged with defaults
		    'menu_icon'  => 'dashicons-book',
		    'public'     => true,
		    'has_archive'=> true,
		    'rewrite'    => array( 'slug' => 'library' ),
		    'show_in_rest' => true,
		    'labels'   => array( 'add_new_item' => __('Add New Book', 'chisel') ),
			)
		);
	}
PHP

Per-CPT default overrides (optional)

  • chisel_default_post_type_supports_{post_type}
  • chisel_default_post_type_rewrite_args_{post_type}

Custom Taxonomies

  • Where: inc/WP/CustomTaxonomies.phpregister_taxonomies()
    • Reads $this->taxonomiesset_taxonomies()apply_filters('chisel_custom_taxonomies', $taxonomies)
    • Applies defaults, then calls RegisterCustomTaxonomy::register_taxonomy()
  • Defaults (set in after_setup_theme via set_properties()):
    • capabilities → filter chisel_default_taxonomy_capabilities
      • Default: manage/edit/delete terms → manage_categories, assign → edit_posts
    • rewrite_args → filter chisel_default_taxonomy_rewrite_args
      • Default: slug empty, with_front, hierarchical, ep_mask
  • Registration (inc/Factory/RegisterCustomTaxonomy.php):
    • Labels auto-generated; can override via labels args.
    • rewrite.slug defaults to the taxonomy name.
    • show_in_rest defaults to true.
  • Additional supported args (opt-in if provided in your taxonomy array): rest_namespace, rest_controller_class, meta_box_cb, default_term, sort, args

Add a Taxonomy (example)

Attach to the CPT above:

private function set_taxonomies() {
		$this->taxonomies = array(
			'genre' => array(
			'singular'     => __('Genre', 'chisel'),
	    'plural'       => __('Genres', 'chisel'),
	    'post_types'   => array( 'book' ),
	    'public'       => true,
	    'hierarchical' => true,
	    'rewrite'      => array( 'slug' => 'genres' ),
	    'show_in_rest' => true,
			)
		);
	}
PHP

Per-taxonomy default overrides (optional)

  • chisel_default_taxonomy_capabilities_{taxonomy}
  • chisel_default_taxonomy_rewrite_args_{taxonomy}

ACF Options Pages

  • Where: inc/WP/Acf.php
    • Base pages set in set_options_pages()
    • Subpages can be added via set_options_sub_pages()
    • On acf/init, arrays are filtered then registered via RegisterAcfOptionsPage
  • Filters:
    • **c**hisel_acf_options_pages for top-level pages
    • chisel_acf_options_sub_page**s** for subpages
  • Registration details (inc/Factory/RegisterAcfOptionsPage.php):
    • Supported keys: page_title (required), menu_title, menu_slug (required), capability, position, redirect, icon_url, post_id, autoload, update_button, updated_message, parent_slug (for subpages)
    • Uses acf_add_options_page() or acf_add_options_sub_page() based on type

Add an ACF Options Page (example)

private function set_options_pages() {
	$this->acf_options_pages = array(
		array(
			'menu_slug'  => 'theme-settings',
	    'page_title' => __('Theme Settings', 'chisel'),
	    'menu_title' => __('Theme Settings', 'chisel'),
	    'icon_url'   => 'dashicons-admin-generic',
	    'position'   => 45,
	    'post_id'    => 'theme_settings',
		),
	);
}

private function set_options_sub_pages() {
		$this->acf_options_sub_pages = array(
			array(
			'menu_slug'  => 'theme-header',
	    'page_title' => __('Header', 'chisel'),
	    'menu_title' => __('Header', 'chisel'),
	    'parent_slug'=> 'theme-settings',
			),
		);
	}
PHP

Practical notes

  • Init order: Defaults set on after_setup_theme (priority 7). Registration runs on init (CPT/Tax) and acf/init (options pages).
  • REST/Editor: Both CPTs and taxonomies default to show_in_rest: true. Disable if needed.
  • Permalinks: Changing rewrite.slug requires visiting Settings → Permalinks to flush rewrite rules.
  • Thumbnails: If a CPT includes thumbnail in supports, it’s propagated to chisel_post_thumbnails_post_types so theme thumbnail support attaches correctly.

Summary

  • Declare CPTs by adding configuration to set_post_types() or set_taxonomies() or via the filters chisel_custom_post_types or chisel_custom_taxonomies; the theme handles consistent defaults and label generation.
  • Fine-tune behavior using per-type default filters and full argument arrays.
  • Add ACF options pages by adding configuration to set_options_pages() or set_options_sub_pages() or through chisel_acf_options_pages / chisel_acf_options_sub_pages filters; the factory wraps acf_add_options_page() safely.

Do you like Chisel?

Give it a star on GitHub!