forked from Develop-With-WP/wp-job-listing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-job-cpt.php
162 lines (111 loc) · 4.48 KB
/
wp-job-cpt.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
function dwwp_register_post_type() {
$singular = __( 'Job Listing' );
$plural = __( 'Job Listings' );
//Used for the rewrite slug below.
$plural_slug = str_replace( ' ', '_', $plural );
//Setup all the labels to accurately reflect this post type.
$labels = array(
'name' => $plural,
'singular_name' => $singular,
'add_new' => 'Add New',
'add_new_item' => 'Add New ' . $singular,
'edit' => 'Edit',
'edit_item' => 'Edit ' . $singular,
'new_item' => 'New ' . $singular,
'view' => 'View ' . $singular,
'view_item' => 'View ' . $singular,
'search_term' => 'Search ' . $plural,
'parent' => 'Parent ' . $singular,
'not_found' => 'No ' . $plural .' found',
'not_found_in_trash' => 'No ' . $plural .' in Trash'
);
//Define all the arguments for this post type.
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 6,
'menu_icon' => 'dashicons-admin-site',
'can_export' => true,
'delete_with_user' => false,
'hierarchical' => false,
'has_archive' => true,
'query_var' => true,
'capability_type' => 'page',
'map_meta_cap' => true,
// 'capabilities' => array(),
'rewrite' => array(
'slug' => strtolower( $plural_slug ),
'with_front' => true,
'pages' => true,
'feeds' => false,
),
'supports' => array(
'title'
)
);
//Create the post type using the above two varaiables.
register_post_type( 'job', $args);
}
add_action( 'init', 'dwwp_register_post_type' );
function dwwp_register_taxonomy() {
$plural = __( 'Locations' );
$singular = __( 'Location' );
$labels = array(
'name' => $plural,
'singular_name' => $singular,
'search_items' => 'Search ' . $plural,
'popular_items' => 'Popular ' . $plural,
'all_items' => 'All ' . $plural,
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => 'Edit ' . $singular,
'update_item' => 'Update ' . $singular,
'add_new_item' => 'Add New ' . $singular,
'new_item_name' => 'New ' . $singular . ' Name',
'separate_items_with_commas' => 'Separate ' . $plural . ' with commas',
'add_or_remove_items' => 'Add or remove ' . $plural,
'choose_from_most_used' => 'Choose from the most used ' . $plural,
'not_found' => 'No ' . $plural . ' found.',
'menu_name' => $plural,
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => strtolower( $singular ) ),
);
register_taxonomy( strtolower( $singular ), 'job', $args );
}
add_action( 'init', 'dwwp_register_taxonomy' );
function dwwp_load_templates( $original_template ) {
if ( get_query_var( 'post_type' ) !== 'job' ) {
return;
}
if ( is_archive() || is_search() ) {
if ( file_exists( get_stylesheet_directory(). '/archive-job.php' ) ) {
return get_stylesheet_directory() . '/archive-job.php';
} else {
return plugin_dir_path( __FILE__ ) . 'templates/archive-job.php';
}
} elseif(is_singular('job')) {
if ( file_exists( get_stylesheet_directory(). '/single-job.php' ) ) {
return get_stylesheet_directory() . '/single-job.php';
} else {
return plugin_dir_path( __FILE__ ) . 'templates/single-job.php';
}
}else{
return get_page_template();
}
return $original_template;
}
add_action( 'template_include', 'dwwp_load_templates' );