This is my first question so bear with me. I'm trying to setup a custom post type which has a few taxonomies associated with it. Each taxonomy is hierarchical. What I would like to achieve is a better url structure than what is happening right now. My permalinks are set to the default "post name" setting. What I would like to achieve is something like this: domain.com/custom-post-type/taxonomy/type
what ends up happening is I just get: domain.com/taxonomy/type
This is essentially a career board where I have different taxonomies representing different categories. For example there is "job sector" for different types of jobs. Should these be set as hierarchical?
When I use a plugin called "Custom Post Type Permalinks" I can get it to work the way I want but I was wondering if its possible without a plugin.
here is my code for the custom post type plugin I've created:
<?php
add_action( 'init', 'career_forum' );
// let's create the function for the custom type
function career_forum() {
$labels = array(
'name' => _x( 'Careers', 'post type general name' ),
'singular_name' => _x( 'Career Listing', 'post type singular name' ),
'add_new' => __( 'Add New', 'career' ),
'add_new_item' => __( 'Add New Career Listing' ),
'edit_item' => __( 'Edit Career Listing' ),
'new_item' => __( 'New Career Listing' ),
'view_item' => __( 'View Career Listing' ),
'search_items' => __( 'Search Careers' ),
'not_found' => __( 'No careers found' ),
'not_found_in_trash' => __( 'No careers found in trash' ),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => true,
'has_archive' => true,
'menu_position' => 5,
'rewrite' => array( 'slug' => 'careers', 'with_front' => false ),
'supports' => array( 'title', 'editor', 'thumbnail')
);
register_post_type( 'career_listings', $args );
}
add_action( 'init', 'create_career_forum_taxonomies', 0 );
// function for adding taxonomies for Career Forum
function create_career_forum_taxonomies() {
// Job Sectors
$labels = array(
'name' => _x( 'Job Sectors', 'taxonomy general name' ),
'singular_name' => _x( 'Job Sector', 'taxonomy singular name' ),
'search_items' => __( 'Search Job Sectors' ),
'all_items' => __( 'All Job Sectors' ),
'parent_item' => __( 'parent Job Sector' ),
'parent_item_colon' => __( 'Parent Job Sector:' ),
'edit_item' => __( 'Edit Job Sector' ),
'update_item' => __( 'Update Job Sector' ),
'add_new_item' => __( 'Add New Job Sector' ),
'new_item_name' => __( 'New Job Sector Name' ),
);
register_taxonomy( 'job_sector',
array( 'career_listings' ),
array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
//'rewrite' => array( 'slug' => 'job-sector', 'hierarchical' => true, 'with_front' => true ),
)
);
// Regions
$labels = array(
'name' => _x( 'Regions', 'taxonomy general name' ),
'singular_name' => _x( 'Region', 'taxonomy singular name' ),
'search_items' => __( 'Search Regions' ),
'all_items' => __( 'All Regions' ),
'parent_item' => __( 'parent Region' ),
'parent_item_colon' => __( 'Parent Region:' ),
'edit_item' => __( 'Edit Region' ),
'update_item' => __( 'Update Region' ),
'add_new_item' => __( 'Add New Region' ),
'new_item_name' => __( 'New Region Name' ),
);
register_taxonomy( 'region',
array( 'career_listings' ),
array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'region', 'hierarchical' => true ),
)
);
// Position Type
$labels = array(
'name' => _x( 'Position Types', 'taxonomy general name' ),
'singular_name' => _x( 'Position Type', 'taxonomy singular name' ),
'search_items' => __( 'Search Position Types' ),
'all_items' => __( 'All Position Types' ),
'parent_item' => __( 'parent Position Type' ),
'parent_item_colon' => __( 'Parent Position Type:' ),
'edit_item' => __( 'Edit Position Type' ),
'update_item' => __( 'Update Position Type' ),
'add_new_item' => __( 'Add New Position Type' ),
'new_item_name' => __( 'New Position Type Name' ),
);
register_taxonomy( 'position_type',
array( 'career_listings' ),
array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'position-type', 'hierarchical' => true ),
)
);
}