Skip to content

Instantly share code, notes, and snippets.

@mrjonwilson
Last active August 30, 2016 13:53
Show Gist options
  • Save mrjonwilson/ef8e4deb0d5dce5ff5d5f1c8e2b9823d to your computer and use it in GitHub Desktop.
Save mrjonwilson/ef8e4deb0d5dce5ff5d5f1c8e2b9823d to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Custom Post Type Plugin
Description: Properties Custom Post Type.
*/
/* Start Adding Functions Below this Line */
// Our custom post type function
function create_posttype() {
register_post_type( 'Properties',
// CPT Options
array(
'labels' => array(
'name' => __( 'Properties' ),
'singular_name' => __( 'Property' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'properties'),
)
);
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
/*
* Creating a function to create our CPT
*/
function custom_post_type() {
// Set UI labels for Custom Post Type
$labels = array(
'name' => _x( 'Properties', 'Post Type General Name', 'fl-automator' ),
'singular_name' => _x( 'Property', 'Post Type Singular Name', 'fl-automator' ),
'menu_name' => __( 'Properties', 'fl-automator' ),
'parent_item_colon' => __( 'Parent Property', 'fl-automator' ),
'all_items' => __( 'All Properties', 'fl-automator' ),
'view_item' => __( 'View Property', 'fl-automator' ),
'add_new_item' => __( 'Add New Property', 'fl-automator' ),
'add_new' => __( 'Add New', 'fl-automator' ),
'edit_item' => __( 'Edit Property', 'fl-automator' ),
'update_item' => __( 'Update Property', 'fl-automator' ),
'search_items' => __( 'Search Property', 'fl-automator' ),
'not_found' => __( 'Not Found', 'fl-automator' ),
'not_found_in_trash' => __( 'Not found in Trash', 'fl-automator' ),
);
// Set other options for Custom Post Type
$args = array(
'label' => __( 'properties', 'fl-automator' ),
'description' => __( 'Property news and reviews', 'fl-automator' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', ),
// You can associate this CPT with a taxonomy or custom taxonomy.
'taxonomies' => array( 'genres' ),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-location-alt',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
// Registering your Custom Post Type
register_post_type( 'properties', $args );
}
/* Hook into the 'init' action so that the function
* Containing our post type registration is not
* unnecessarily executed.
*/
add_action( 'init', 'custom_post_type', 0 );
/* Stop Adding Functions Below this Line */
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment