Return to Snippet

Revision: 30376
at August 13, 2010 01:32 by jamiebrwr


Initial Code
/******* CUSTOM POST TYPE: PROVIDERS *********/

add_action('init', 'prov_register');

function prov_register() {
	$args = array(
		'label' => __('Providers'),
		'singular_label' => __('Provider'),
		'public' => true,
		'show_ui' => true,
		'capability_type' => 'post',
		'hierarchical' => false,
		'rewrite' => true,
		'supports' => array('title', 'thumbnail')
	);

	register_post_type( 'provider' , $args );
}

	add_action("admin_init", "prov_admin_init");
	add_action('save_post', 'save_prov_meta');

	function prov_admin_init(){
		add_meta_box("prov_meta", "Provider Options", "prov_meta_options", "provider", "normal", "core");
	}

	function prov_meta_options(){
		global $post;
		$custom = get_post_custom($post->ID);
		$prov_suffix = $custom["prov_suffix"][0];
		$prov_specialty = $custom["prov_specialty"][0];
	
?>
	<div style="float:left;padding:5px 15px;">
		<label for="prov_suffix">Suffix </label>
		<input type="text" name="prov_suffix" size="20" autocomplete="on" value="<?php echo $prov_suffix; ?>">
	</div>
	<div style="float:left;padding:5px 15px;">
		<label for="prov_specialty">Specialty </label>
		<input type="text" name="prov_specialty" size="30" autocomplete="on" value="<?php echo $prov_specialty; ?>">
	</div>
	<p>&nbsp;</p>
	<p>&nbsp;</p>
<?php
	}

function save_prov_meta(){
	global $post;
	update_post_meta($post->ID, "prov_suffix", $_POST["prov_suffix"]);
	update_post_meta($post->ID, "prov_specialty", $_POST["prov_specialty"]);
}

register_taxonomy("clinic", array("provider"), array("hierarchical" => false, "label" => "Clinics", "singular_label" => "Clinic", "rewrite" => true));

add_filter("manage_edit-provider_columns", "prov_edit_columns");
add_action("manage_posts_custom_column",  "prov_custom_columns");

function prov_edit_columns($columns){
		$columns = array(
			"cb" => "<input type=\"checkbox\" />",
			"title" => "Name",
			"prov_suffix" => "Suffix",
			"prov_specialty" => "Specialty",
			"clinic" => "Clinic(s)",
			"prov_image" => "Featured Image"
		);

		return $columns;
}

function prov_custom_columns($column){
		global $post;
		switch ($column)
		{
			case "prov_suffix":
				$custom = get_post_custom();
				echo $custom["prov_suffix"][0];
				break;
			case "prov_specialty":
				$custom = get_post_custom();
				echo $custom["prov_specialty"][0];
				break;
			case "clinic":
				echo get_the_term_list($post->ID, 'clinic', '', ', ','');
				break;
			case "prov_image":
				echo "<img src=\"" . get_thumbnail($post->ID,"60","75") . "\" />";
				break;
		}
}

Initial URL

                                

Initial Description
Place into fucntions.php

Initial Title
Custom Post Type: Providers

Initial Tags
wordpress

Initial Language
PHP