jmccole83
1/7/2019 - 10:16 AM

Sage 9 ACF Custom Post Types & Options Page

Add functions for Custom Post Types & ACF Custom Options Pages to it's own file for better segregation, e.g. below snippet. See 'Sage 9 - Required Files' for info on file location and inclusion.

<?php

namespace App;

// clients
add_action( 'init', function () {
  $labels = array(
    "name" => __( 'Clients', '' ),
    "all_items" => __( 'Clients', '' ),
    "singular_name" => __( 'Client', '' ),
    "add_new" => __( 'Add client', '' ),
    "add_new_item" => __( 'Add client', '' ),
  );

  $args = array(
    "label" => __( 'Clients', '' ),
    "labels" => $labels,
    "description" => "Client post type",
    "supports" => array( "title", "revisions", "thumbnail", "editor" ),
    "public" => true,
    "show_ui" => true,
    "show_in_rest" => true,
    "rest_base" => "",
    "has_archive" => false,
    "show_in_menu" => true,
    "menu_icon" => 'dashicons-groups',
    "exclude_from_search" => true,
    "capability_type" => "post",
    "map_meta_cap" => true,
    "hierarchical" => false,
  );
  // rename to collaboration
  register_post_type( "client", $args );
});

// Register Facilities
$args = array(
    'hierarchical'      => true,
    'has_archive' 		  => false,
    'labels'            => array(
      "name"            => __( 'Facilities', '' ),
      "singular_name"   => __( 'Facility', '' ),
      "add_new"         => __( 'Add Facility', '' ),
      "add_new_item"    => __( 'Add Facility', '' ),
    ),
    'public'			      => true,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'facilities' ),
);
register_taxonomy( 'facilities', array( 'sites' ), $args );

if (function_exists('acf_add_options_page')) {
	$site_title = get_bloginfo();
	acf_add_options_page(array(
		'page_title' => $site_title . ' theme settings',
		'menu_title' => 'Theme Settings',
		'menu_slug'  => 'theme-general-settings',
		'capability' => 'manage_options',
		'redirect'   => false,
		'position'   => 20,
	));
}