Created
June 29, 2011 21:51
-
-
Save mattboon/1055097 to your computer and use it in GitHub Desktop.
WordPress Custom Post Type
This file contains 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
<?php | |
//---- CUSTOM POST TYPE - EXECUTIVE DEVELOPERS -------------------------------------------------------- | |
add_action('init', '_init_developer_post_type'); | |
function _init_developer_post_type() { | |
// MAKE POST TYPE | |
//--------------------------- | |
register_post_type( 'developer', | |
array( | |
'labels' => array( | |
'name' => __( 'Developers' ), | |
'singular_name' => __( 'Developer' ), | |
'add_new' => __( 'Add New' ), | |
'add_new_item' => __( 'Add New Developer' ), | |
'edit' => __( 'Edit' ), | |
'edit_item' => __( 'Edit Developer' ), | |
'new_item' => __( 'New Developer' ), | |
'view' => __( 'View Developer' ), | |
'view_item' => __( 'View Developer' ), | |
'search_items' => __( 'Search Developers' ), | |
'not_found' => __( 'No Developers found' ), | |
'not_found_in_trash' => __( 'No Developers found in Trash' ), | |
), | |
'public' => true, | |
'show_ui' => true, | |
'publicly_queryable' => true, | |
'exclude_from_search' => false, | |
'hierarchical' => false, | |
'menu_position' => 20, | |
'capability_type' => 'post', | |
//'menu_icon' => '/assets/images/faq_menu.png', | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'about/people/executive-developers', 'with_front' => false ), | |
'supports' => array('title', 'editor'), | |
) | |
); | |
// MAKE TAXONOMY | |
//--------------------------- | |
register_taxonomy_for_object_type('devloper', 'developer-region'); | |
register_taxonomy( | |
'developer-region', | |
array( 'developer' ), | |
array( | |
'labels' => array( | |
'name' => __( 'Regions' ), | |
'singular_name' => __( 'Region' ), | |
'search_items' => __( 'Search Regions' ), | |
'popular_items' => __( 'Popular Regions' ), | |
'all_items' => __( 'All Regions' ), | |
'parent_item' => __( 'Parent Region' ), | |
'parent_item_colon' => __( 'Parent Region:' ), | |
'edit_item' => __( 'Edit Region' ), | |
'update_item' => __( 'Update Region' ), | |
'add_new_item' => __( 'Add Region' ), | |
'new_item_name' => __( 'New Region' ), | |
), | |
'public' => true, | |
'show_in_nav_menus' => true, | |
'show_ui' => true, | |
'publicly_queryable' => true, | |
'exclude_from_search' => false, | |
//'rewrite' => array( 'slug' => 'topics', 'with_front' => false ), | |
'hierarchical' => true, | |
'query_var' => true, | |
) | |
); | |
// DEFINE CUSTOM COLUMNS | |
//--------------------------- | |
add_filter("manage_edit-developer_columns", "developer_define_columns"); | |
function developer_define_columns($question_columns) { | |
$new_columns['cb'] = '<input type="checkbox" />'; | |
$new_columns['title'] = __('Developer'); | |
$new_columns['developer-surname'] = __('Surname'); | |
$new_columns['developer-region'] = __('Region'); | |
//$new_columns['question-answer'] = __('Answer'); | |
//$new_columns['author'] = __('Author'); | |
//$new_columns['comments'] = __('Comments'); | |
//$new_columns['tags'] = __('Tags'); | |
//$new_columns['date'] = __('Date'); | |
//$new_columns['hsm_pagetitle'] = __('Page title'); | |
//$new_columns['hsm_pagedescription'] = __('Page description'); | |
return $new_columns; | |
} | |
// POPULATE CUSTOM COLUMNS | |
//--------------------------- | |
add_action('manage_developer_posts_custom_column', 'developer_fill_columns', 10, 2); | |
function developer_fill_columns($column_name, $id) { | |
global $post; | |
switch ($column_name) { | |
case 'developer-surname': | |
echo get_post_meta($id, 'developer_surname', true); | |
break; | |
case 'developer-region': | |
echo strip_tags(get_the_term_list( $id, 'developer-region', '', ', ', '' )); | |
break; | |
default: | |
break; | |
} | |
} | |
// SORTABLE COLUMN HEADERS | |
//--------------------------- | |
add_filter("manage_edit-developer_sortable_columns", 'developer_sortable_columns'); | |
function developer_sortable_columns($columns) { | |
$custom = array( | |
'developer-surname' => 'developer-surname', | |
'developer-region' => 'developer-region' | |
); | |
return wp_parse_args($custom, $columns); | |
/* or this way | |
$columns['concertdate'] = 'concertdate'; | |
$columns['city'] = 'city'; | |
return $columns; | |
*/ | |
} | |
} | |
// ADD HEADSPACE TO CUSTOM POST TYPE | |
//--------------------------- | |
add_action( 'admin_init', '_admit_init_headpspace_boxes' ); | |
function _admit_init_headpspace_boxes() { | |
global $headspace2; | |
if ( function_exists( 'add_meta_box' ) && is_object( $headspace2 ) ) { | |
add_meta_box( 'headspacestuff', __('HeadSpace', 'headspace'), array( &$headspace2, 'metabox' ), 'developer', 'normal', 'high' ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment