Custom Post Type: Providers


/ Published in: PHP
Save to your folder(s)

Place into fucntions.php


Copy this code and paste it in your HTML
  1. /******* CUSTOM POST TYPE: PROVIDERS *********/
  2.  
  3. add_action('init', 'prov_register');
  4.  
  5. function prov_register() {
  6. $args = array(
  7. 'label' => __('Providers'),
  8. 'singular_label' => __('Provider'),
  9. 'public' => true,
  10. 'show_ui' => true,
  11. 'capability_type' => 'post',
  12. 'hierarchical' => false,
  13. 'rewrite' => true,
  14. 'supports' => array('title', 'thumbnail')
  15. );
  16.  
  17. register_post_type( 'provider' , $args );
  18. }
  19.  
  20. add_action("admin_init", "prov_admin_init");
  21. add_action('save_post', 'save_prov_meta');
  22.  
  23. function prov_admin_init(){
  24. add_meta_box("prov_meta", "Provider Options", "prov_meta_options", "provider", "normal", "core");
  25. }
  26.  
  27. function prov_meta_options(){
  28. global $post;
  29. $custom = get_post_custom($post->ID);
  30. $prov_suffix = $custom["prov_suffix"][0];
  31. $prov_specialty = $custom["prov_specialty"][0];
  32.  
  33. ?>
  34. <div style="float:left;padding:5px 15px;">
  35. <label for="prov_suffix">Suffix </label>
  36. <input type="text" name="prov_suffix" size="20" autocomplete="on" value="<?php echo $prov_suffix; ?>">
  37. </div>
  38. <div style="float:left;padding:5px 15px;">
  39. <label for="prov_specialty">Specialty </label>
  40. <input type="text" name="prov_specialty" size="30" autocomplete="on" value="<?php echo $prov_specialty; ?>">
  41. </div>
  42. <p>&nbsp;</p>
  43. <p>&nbsp;</p>
  44. <?php
  45. }
  46.  
  47. function save_prov_meta(){
  48. global $post;
  49. update_post_meta($post->ID, "prov_suffix", $_POST["prov_suffix"]);
  50. update_post_meta($post->ID, "prov_specialty", $_POST["prov_specialty"]);
  51. }
  52.  
  53. register_taxonomy("clinic", array("provider"), array("hierarchical" => false, "label" => "Clinics", "singular_label" => "Clinic", "rewrite" => true));
  54.  
  55. add_filter("manage_edit-provider_columns", "prov_edit_columns");
  56. add_action("manage_posts_custom_column", "prov_custom_columns");
  57.  
  58. function prov_edit_columns($columns){
  59. $columns = array(
  60. "cb" => "<input type=\"checkbox\" />",
  61. "title" => "Name",
  62. "prov_suffix" => "Suffix",
  63. "prov_specialty" => "Specialty",
  64. "clinic" => "Clinic(s)",
  65. "prov_image" => "Featured Image"
  66. );
  67.  
  68. return $columns;
  69. }
  70.  
  71. function prov_custom_columns($column){
  72. global $post;
  73. switch ($column)
  74. {
  75. case "prov_suffix":
  76. $custom = get_post_custom();
  77. echo $custom["prov_suffix"][0];
  78. break;
  79. case "prov_specialty":
  80. $custom = get_post_custom();
  81. echo $custom["prov_specialty"][0];
  82. break;
  83. case "clinic":
  84. echo get_the_term_list($post->ID, 'clinic', '', ', ','');
  85. break;
  86. case "prov_image":
  87. echo "<img src=\"" . get_thumbnail($post->ID,"60","75") . "\" />";
  88. break;
  89. }
  90. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.