Posted By

jamiebrwr on 08/13/10


Tagged

wordpress


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

simonbouchard
jamalmohamed
maxvee8
manavecplan
marclarr
booski
ToddSmithSalter


Custom Post Types: Jobs


 / Published in: PHP
 

Place into fucntions.php

  1. /******* CUSTOM POST TYPE: JOBS *********/
  2.  
  3. add_action('init', 'job_register');
  4.  
  5. function job_register() {
  6. $args = array(
  7. 'label' => __('Jobs'),
  8. 'singular_label' => __('Job'),
  9. 'public' => true,
  10. 'show_ui' => true,
  11. 'capability_type' => 'post',
  12. 'hierarchical' => false,
  13. 'rewrite' => true,
  14. 'supports' => array('title', 'editor')
  15. );
  16.  
  17. register_post_type( 'job' , $args );
  18. }
  19.  
  20. add_action("admin_init", "job_admin_init");
  21. add_action('save_post', 'save_job_meta');
  22.  
  23. function job_admin_init(){
  24. add_meta_box("job_meta", "Job Options", "job_meta_options", "job", "normal", "core");
  25. }
  26.  
  27. function job_meta_options(){
  28. global $post;
  29. $custom = get_post_custom($post->ID);
  30. $job_clinic = $custom["job_clinic"][0];
  31. $job_supervisor = $custom["job_supervisor"][0];
  32. $job_type = $custom["job_type"][0];
  33. $job_hours = $custom["job_hours"][0];
  34. $job_salary = $custom["job_salary"][0];
  35. $job_salarytype = $custom["job_salarytype"][0];
  36.  
  37. ?>
  38. <h2 style="clear:left;margin:20px 0 0 15px;">Location</h2>
  39. <div style="float:left;padding:5px 15px;">
  40. <label for="job_clinic">Clinic </label>
  41. <input type="text" name="job_clinic" size="30" autocomplete="on" value="<?php echo $job_clinic; ?>">
  42. </div>
  43. <div style="float:left;padding:5px 15px;">
  44. <label for="job_supervisor">Supervisor </label>
  45. <input type="text" name="job_supervisor" size="30" autocomplete="on" value="<?php echo $job_supervisor; ?>">
  46. </div>
  47. <div style="float:left;clear:left;">
  48. <h2 style="clear:left;margin:20px 0 0 15px;">Details</h2>
  49. <div style="float:left;padding:5px 15px;">
  50. <label for="job_type">Type </label>
  51. <select name="job_type" id="job_type">
  52. <option value="">Select one</option>
  53. <option value="Full Time"<?php if ($job_type=="Full Time") echo " selected" ?>>Full Time</option>
  54. <option value="Part Time"<?php if ($job_type=="Part Time") echo " selected" ?>>Part Time</option>
  55. <option value="Temporary Full Time"<?php if ($job_type=="Temporary Full Time") echo " selected" ?>>Temporary Full Time</option>
  56. <option value="Temporary Part Time"<?php if ($job_type=="Temporary Part Time") echo " selected" ?>>Temporary Part Time</option>
  57. </select>
  58. </div>
  59. <div style="float:left;padding:5px 15px;">
  60. <label for="job_hours">Hours </label>
  61. <input type="text" name="job_hours" size="5" autocomplete="on" value="<?php echo $job_hours; ?>">
  62. </div>
  63. <div style="float:left;padding:5px 15px;">
  64. <label for="job_salary">Salary $</label>
  65. <input type="text" name="job_salary" size="10" autocomplete="on" value="<?php echo $job_salary; ?>">
  66. <select name="job_salarytype" id="job_salarytype">
  67. <option value="">Select one</option>
  68. <option value="per Hour"<?php if ($job_salarytype=="per Hour") echo " selected" ?>>per Hour</option>
  69. <option value="per Week"<?php if ($job_salarytype=="per Week") echo " selected" ?>>per Week</option>
  70. <option value="per Year"<?php if ($job_salarytype=="per Year") echo " selected" ?>>per Year</option>
  71. </select>
  72. </div>
  73. </div>
  74. <p>&nbsp;</p>
  75. <p>&nbsp;</p>
  76. <p>&nbsp;</p>
  77. <p>&nbsp;</p>
  78. <p>&nbsp;</p>
  79. <p>&nbsp;</p>
  80. <p>&nbsp;</p>
  81. <?php
  82. }
  83.  
  84. function save_job_meta(){
  85. global $post;
  86. update_post_meta($post->ID, "job_clinic", $_POST["job_clinic"]);
  87. update_post_meta($post->ID, "job_supervisor", $_POST["job_supervisor"]);
  88. update_post_meta($post->ID, "job_type", $_POST["job_type"]);
  89. update_post_meta($post->ID, "job_hours", $_POST["job_hours"]);
  90. update_post_meta($post->ID, "job_salary", $_POST["job_salary"]);
  91. update_post_meta($post->ID, "job_salarytype", $_POST["job_salarytype"]);
  92. }
  93.  
  94. add_filter("manage_edit-job_columns", "job_edit_columns");
  95. add_action("manage_posts_custom_column", "job_custom_columns");
  96.  
  97. function job_edit_columns($columns){
  98. $columns = array(
  99. "cb" => "<input type=\"checkbox\" />",
  100. "title" => "Name",
  101. "job_clinic" => "Clinic",
  102. "job_supervisor" => "Supervisor",
  103. "job_type" => "Type",
  104. "job_hours" => "Hours",
  105. "job_salary" => "Salary",
  106. );
  107.  
  108. return $columns;
  109. }
  110.  
  111. function job_custom_columns($column){
  112. global $post;
  113. switch ($column)
  114. {
  115. case "job_clinic":
  116. $custom = get_post_custom();
  117. echo $custom["job_clinic"][0];
  118. break;
  119. case "job_supervisor":
  120. $custom = get_post_custom();
  121. echo $custom["job_supervisor"][0];
  122. break;
  123. case "job_type":
  124. $custom = get_post_custom();
  125. echo $custom["job_type"][0];
  126. break;
  127. case "job_hours":
  128. $custom = get_post_custom();
  129. echo $custom["job_hours"][0];
  130. break;
  131. case "job_salary":
  132. $custom = get_post_custom();
  133. $test=$custom["job_salary"][0]; if(!empty($test)): echo "$ " . $custom["job_salary"][0]; endif;
  134. echo " " . $custom["job_salarytype"][0];
  135. break;
  136. }
  137. }

Report this snippet  

You need to login to post a comment.