Agency Custom Post Type
This file contains the code necessary to create a new Custom Post Type in WordPress called 'Agency', which includes several custom fields such as Website URL, City, State, ZIP, and Phone #. The code makes it possible to manage and categorize agency-related content separately from posts and pages. It uses the Advanced Custom Fields plugin for additional metadata associated with each agency entry.
<?php // Register Custom Post Type Agency function create_agency_cpt() { $labels = array( 'name' => _x( 'Agencies', 'Post Type General Name', 'text_domain' ), 'singular_name' => _x( 'Agency', 'Post Type Singular Name', 'text_domain' ), ); $args = array( 'label' => __( 'Agency', 'text_domain' ), 'labels' => $labels, 'supports' => array('title', 'editor', 'thumbnail'), 'public' => true, 'show_in_menu' => true, 'menu_position' => 5, 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => true, 'hierarchical' => false, 'exclude_from_search' => false, 'show_ui' => true, 'show_in_rest' => true, ); register_post_type( 'agency', $args ); } add_action( 'init', 'create_agency_cpt', 0 ); if( function_exists('acf_add_local_field_group') ): acf_add_local_field_group(array( 'key' => 'group_1', 'title' => 'Agency Fields', 'fields' => array( array( 'key' => 'field_1', 'label' => 'Website URL', 'name' => 'website_url', 'type' => 'url', ), array( 'key' => 'field_2', 'label' => 'City', 'name' => 'city', 'type' => 'text', ), array( 'key' => 'field_3', 'label' => 'State', 'name' => 'state', 'type' => 'text', ), array( 'key' => 'field_4', 'label' => 'ZIP', 'name' => 'zip', 'type' => 'text', ), array( 'key' => 'field_5', 'label' => 'Phone #', 'name' => 'phone', 'type' => 'text', ), ), 'location' => array( array( array( 'param' => 'post_type', 'operator' => '==', 'value' => 'agency', ), ), ), )); endif; ?>
Frequently Asked Questions
Custom Post Types allow users to create collections of content in WordPress that have a distinct separation from posts and pages.