Created
July 21, 2015 10:32
-
-
Save andrewahead4/d242218faddbd50db797 to your computer and use it in GitHub Desktop.
Sample of a WordPress custom post type set up for a DataFlexor Gym example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'init', 'register_cpt_gym' ); | |
function register_cpt_gym() { | |
$labels = array( | |
'name' => _x( 'Gyms', 'gym' ), | |
'singular_name' => _x( 'Gym', 'gym' ), | |
'add_new' => _x( 'Add New', 'gym' ), | |
'add_new_item' => _x( 'Add New', 'gym' ), | |
'edit_item' => _x( 'Edit', 'gym' ), | |
'new_item' => _x( 'New', 'gym' ), | |
'view_item' => _x( 'View', 'gym' ), | |
'search_items' => _x( 'Search Gyms', 'gym' ), | |
'not_found' => _x( 'No Gyms found', 'gym' ), | |
'not_found_in_trash' => _x( 'No Gyms found in Trash', 'gym' ), | |
'parent_item_colon' => _x( 'Parent Gym:', 'gym' ), | |
'menu_name' => _x( 'Gyms', 'gym' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => true, | |
'description' => 'Franko\'s Gyms', | |
'supports' => array( 'title', 'editor', 'custom-fields', 'comments', 'revisions', 'page-attributes' ), | |
'taxonomies' => array( 'category', 'post_tag', ), | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'show_in_nav_menus' => true, | |
'publicly_queryable' => true, | |
'exclude_from_search' => false, | |
'has_archive' => true, | |
'query_var' => true, | |
'can_export' => true, | |
'rewrite' => true, | |
'capability_type' => 'page' | |
); | |
register_post_type( 'gym', $args ); | |
} | |
/** | |
* Add custom taxonomies | |
* | |
* Additional custom taxonomies can be defined here | |
* http://codex.wordpress.org/Function_Reference/register_taxonomy | |
*/ | |
function add_custom_taxonomies_gym() { | |
// Add new "Locations" taxonomy to Posts | |
register_taxonomy('gym_dftype', 'gym', array( | |
// Hierarchical taxonomy (like categories) | |
'hierarchical' => true, | |
// This array of options controls the labels displayed in the WordPress Admin UI | |
'labels' => array( | |
'name' => _x( 'Gym Types', 'taxonomy general name', 'gym' ), | |
'singular_name' => _x( 'Gym Type', 'taxonomy singular name', 'gym' ), | |
'search_items' => __( 'Search Gym Types', 'gym' ), | |
'all_items' => __( 'All Gym Types', 'gym' ), | |
'parent_item' => __( 'Parent Gym Type', 'gym' ), | |
'parent_item_colon' => __( 'Parent Gym Type:', 'gym' ), | |
'edit_item' => __( 'Edit Gym Type' ), | |
'update_item' => __( 'Update Gym Type', 'gym' ), | |
'add_new_item' => __( 'Add New Gym Type', 'gym' ), | |
'new_item_name' => __( 'New Gym Type Name', 'gym' ), | |
'menu_name' => __( 'Gym Types' ), | |
), | |
// Control the slugs used for this taxonomy | |
'rewrite' => array( | |
'slug' => 'gym_dftypes', // This controls the base slug that will display before each term | |
'with_front' => false, // Don't display the category base before "/locations/" | |
'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/" | |
), | |
)); | |
} | |
add_action( 'init', 'add_custom_taxonomies_gym', 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment