Skip to content

Instantly share code, notes, and snippets.

@astockwell
Last active December 16, 2015 13:59
Show Gist options
  • Save astockwell/5445600 to your computer and use it in GitHub Desktop.
Save astockwell/5445600 to your computer and use it in GitHub Desktop.
Pristine Wordpress Custom Post Type (and Related Custom Taxonomy) Declaration
<?php
function xyz_create_cpt_animal() {
$label_singular = 'Animal';
$label_plural = $label_singular . 's';
$labels = array(
'name' => __($label_plural),
'singular_name' => __($label_singular),
'add_new' => __('Add New'),
'add_new_item' => __('Add New ' . $label_singular),
'edit_item' => __('Edit ' . $label_singular),
'new_item' => __('New ' . $label_singular),
'all_items' => __('All ' . $label_plural),
'view_item' => __('View ' . $label_singular),
'search_items' => __('Search ' . $label_plural),
'not_found' => __( 'No ' . $label_plural . ' found'),
'not_found_in_trash' => __('No ' . $label_plural . ' found in Trash'),
'parent_item_colon' => __(''),
'menu_name' => __($label_plural)
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'hierarchical' => false,
// 'rewrite' => array( 'with_front' => false, 'slug' => 'animal' ),
// 'show_in_menu' => true,
// 'menu_position' => 5,
'menu_icon' => 'dashicons-portfolio', // via http://melchoyce.github.io/dashicons/
'supports' => array(
'title',
'editor',
// 'author',
// 'thumbnail',
// 'excerpt',
// 'trackbacks',
// 'custom-fields',
// 'comments',
// 'post-formats',
'revisions',
'page-attributes'
)
);
register_post_type( 'animal', $args ); // Singular! Underscores!
}
add_action( 'init', 'xyz_create_cpt_animal' );
function xyz_create_tax_species() {
$label_singular = 'Program Area';
$label_plural = $label_singular . 's';
$labels = array(
'name' => __($label_plural),
'singular_name' => __($label_singular),
'search_items' => __('Search ' . $label_plural),
'popular_items' => __('Popular ' . $label_plural),
'all_items' => __('All ' . $label_plural),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __('Edit ' . $label_singular),
'update_item' => __('Update ' . $label_singular),
'add_new_item' => __('Add New ' . $label_singular),
'new_item_name' => __('New ' . $label_singular . ' Name'),
'separate_items_with_commas' => __('Separate ' . $label_plural . ' with commas'),
'add_or_remove_items' => __('Add or remove ' . $label_plural),
'choose_from_most_used' => __('Choose from the most used ' . $label_plural),
'not_found' => __('No ' . $label_plural . ' found.'),
'menu_name' => __($label_plural),
);
$post_types = array(
'animal'
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
// 'rewrite' => array( 'slug' => 'species' ),
// 'sort' => true,
'query_var' => true,
);
register_taxonomy( 'program_areas', $post_types, $args ); // Plural! Underscores!
}
add_action( 'init', 'xyz_create_tax_species', 0 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment