Guest User

Untitled

a guest
Dec 17th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. // Custom Post Types
  2. function wpt_job_post_type() {
  3. $labels = array(
  4. 'name' => 'Vacancies',
  5. 'singular_name' => 'Job Opportunity',
  6. 'add_new' => 'Add New Job',
  7. 'add_new_item' => 'Add New Job Opportunity',
  8. 'edit_item' => 'Edit Job',
  9. 'new_item' => 'New Job Opportunity',
  10. 'view_item' => 'View Job',
  11. 'search_items' => 'Search Careers',
  12. 'not_found' => 'No jobs found',
  13. 'not_found_in_trash' => 'No jobs found in Trash',
  14. 'parent_item_colon' => 'Parent Job:'
  15. );
  16. $supports = array(
  17. 'title',
  18. 'editor',
  19. 'thumbnail',
  20. 'comments',
  21. 'revisions',
  22. );
  23. $args = array(
  24. 'labels' => $labels,
  25. 'supports' => $supports,
  26. 'public' => true,
  27. 'exclude_from_search' => false,
  28. 'map_meta_cap'=> true,
  29. 'capability_type' => 'post',
  30. 'rewrite' => array(
  31. 'slug' => 'vacancies',
  32. 'with_front' => true,
  33. 'pages' => true,
  34. 'feeds' => 'careers'
  35. ),
  36. 'has_archive' => true,
  37. 'menu_position' => 30,
  38. 'menu_icon' => 'dashicons-businessman',
  39. 'taxonomies' => array('job-category'),
  40. );
  41. register_post_type( 'vacancies', $args );
  42. }
  43. add_action( 'init', 'wpt_job_post_type' );
  44.  
  45. register_taxonomy( 'job-category', array('vacancies'),
  46. array(
  47. 'hierarchical' => true,
  48. 'rewrite' => array('slug' => 'vacancies/job-category'),
  49. 'query_var' => '',
  50. 'public' => true,
  51. 'show_ui' => true,
  52. 'show_tagcloud' => true,
  53. 'labels' => array(
  54. 'name' => 'Job Categories',
  55. 'singular_name' => 'Job Category',
  56. 'search_items' => 'Search Job Categories',
  57. 'popular_items' => 'Popular Job Categories',
  58. 'all_items' => 'All Job Categories',
  59. 'parent_item' => 'Parent Job Category',
  60. 'parent_item_colon' => 'Parent Job Category:',
  61. 'edit_item' => 'Edit Job Category',
  62. 'update_item' => 'Update Job Category',
  63. 'add_new_item' => 'Add New Job Category',
  64. 'new_item_name' => 'New Job Category Name',
  65. 'separate_items_with_commas' => 'Separate job categories with commas',
  66. 'add_or_remove_items' => 'Add or remove job categories',
  67. 'choose_from_most_used' => 'Choose from the most used job categories'
  68. ),
  69. 'capabilities' => array(
  70. 'manage_terms' => 'manage_categories',
  71. 'edit_terms' => 'manage_categories',
  72. 'delete_terms' => 'manage_categories',
  73. 'assign_terms' => 'edit_posts'
  74. ),
  75. 'show_in_nav_menus' => true
  76. )
  77. );
  78.  
  79. // Preload taxonomy with some common terms
  80. $job_category_preload_terms = array(
  81. 'Nurse',
  82. 'Civil Engineer',
  83. 'Electrician'
  84. );
  85. foreach($job_category_preload_terms as $job_category_term){
  86. wp_insert_term($job_category_term, 'job-category');
  87. }
  88.  
  89. add_filter('single_template','job_single');
  90. add_filter('archive_template','job_archive');
  91.  
  92. //route single- template
  93. function job_single($single_template){
  94. global $post;
  95. $found = locate_template('single-job.php');
  96. if($post->post_type == 'vacancies' && $found != ''){
  97. $single_template = dirname(__FILE__).'/single-job.php';
  98. }
  99. return $single_template;
  100. }
  101.  
  102. //route archive- template
  103. function job_archive($template){
  104. if(is_post_type_archive('vacancies')){
  105. $theme_files = array('archive-job.php');
  106. $exists_in_theme = locate_template($theme_files, false);
  107. return dirname(__FILE__) . '/archive-job.php';
  108. }
  109. return $template;
  110. }
Add Comment
Please, Sign In to add comment