Created
September 27, 2017 13:38
-
-
Save anonymous/6322550e14834850bb3a7c5fae0e3d8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Custom Post Type Setup */ | |
function post_type_jobs() { | |
$labels = array( | |
'name' => _x('Jobs', 'post type general name', 'agrg'), | |
'singular_name' => _x('Jobs', 'post type singular name', 'agrg'), | |
'add_new' => _x('Add New Job', 'jobs', 'agrg'), | |
'add_new_item' => __('Add New Job', 'agrg'), | |
'edit_item' => __('Edit Job', 'agrg'), | |
'new_item' => __('New Job', 'agrg'), | |
'view_item' => __('View Job', 'agrg'), | |
'search_items' => __('Search Jobs', 'agrg'), | |
'not_found' => __('No Jobs found', 'agrg'), | |
'not_found_in_trash' => __('No Jobs found in Trash', 'agrg'), | |
'parent_item_colon' => '' | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'publicly_queryable' => true, | |
'show_ui' => true, | |
'query_var' => true, | |
'capability_type' => 'post', | |
'hierarchical' => true, | |
'menu_position' => null, | |
'menu_icon' => 'dashicons-menu', | |
'has_archive' => true, | |
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'page-attributes', 'post-formats' ) | |
); | |
register_post_type( 'jobs', $args ); | |
flush_rewrite_rules(false); | |
} | |
add_action('init', 'post_type_jobs'); | |
function be_register_taxonomies() { | |
$taxonomies = array( | |
array( | |
'slug' => 'job-department', | |
'single_name' => 'Department', | |
'plural_name' => 'Departments', | |
'post_type' => 'jobs', | |
'rewrite' => array( 'slug' => 'department' ), | |
), | |
array( | |
'slug' => 'job-type', | |
'single_name' => 'Type', | |
'plural_name' => 'Types', | |
'post_type' => 'jobs', | |
'hierarchical' => false, | |
), | |
array( | |
'slug' => 'job-experience', | |
'single_name' => 'Min-Experience', | |
'plural_name' => 'Min-Experiences', | |
'post_type' => 'jobs', | |
), | |
); | |
foreach( $taxonomies as $taxonomy ) { | |
$labels = array( | |
'name' => $taxonomy['plural_name'], | |
'singular_name' => $taxonomy['single_name'], | |
'search_items' => 'Search ' . $taxonomy['plural_name'], | |
'all_items' => 'All ' . $taxonomy['plural_name'], | |
'parent_item' => 'Parent ' . $taxonomy['single_name'], | |
'parent_item_colon' => 'Parent ' . $taxonomy['single_name'] . ':', | |
'edit_item' => 'Edit ' . $taxonomy['single_name'], | |
'update_item' => 'Update ' . $taxonomy['single_name'], | |
'add_new_item' => 'Add New ' . $taxonomy['single_name'], | |
'new_item_name' => 'New ' . $taxonomy['single_name'] . ' Name', | |
'menu_name' => $taxonomy['plural_name'] | |
); | |
$rewrite = isset( $taxonomy['rewrite'] ) ? $taxonomy['rewrite'] : array( 'slug' => $taxonomy['slug'] ); | |
$hierarchical = isset( $taxonomy['hierarchical'] ) ? $taxonomy['hierarchical'] : true; | |
register_taxonomy( $taxonomy['slug'], $taxonomy['post_type'], array( | |
'hierarchical' => $hierarchical, | |
'labels' => $labels, | |
'show_ui' => true, | |
'query_var' => true, | |
'rewrite' => $rewrite, | |
)); | |
} | |
} | |
add_action( 'init', 'be_register_taxonomies', 0 ); | |
/* Rewrite Rule */ | |
function custom_rewrite_rules() { | |
add_rewrite_rule('^job-department/(.*)/job-type/(.*)?', 'index.php?job-department=$matches[1]&job-type=$matches[2]', 'top'); | |
} | |
add_action('init', 'custom_rewrite_rules'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment