I always seem to find my own solution minutes after posting here... here goes, for people having the same issue, make sure the slug in both the registration of the custom post type and the taxonomy is the same... Also make sure you use the generator, as it is easy to miss something... So now i am getting both bases working all right no issues at all! :)
Edit: So, whatever base you use in your general settings will work for all your normal posts but with the added function and tying everything right, all custom ones will be rewritten. Hope this helps!
<?php
/**
* Register Custom Post Type
*/
function create_post_type() {
register_post_type( 'our_work', array(
'label' => 'Work Items',
'singular_label' => 'Work Item',
'description' => 'Our work items',
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'has_archive' => true,
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'revisions', 'thumbnail', 'page-attributes' ),
'rewrite' => array( 'slug' => 'work-items/%work-categories%', 'with_front' => false),
)
);
}
add_action( 'init', 'create_post_type' );
/**
* Register Custom Taxonomy
*/
function create_taxonomies() {
$labels = array(
'name' => 'work-categories',
'singular_name' => 'work-category',
'menu_name' => 'Work Categories',
'all_items' => 'All Items',
'parent_item' => 'Parent Item',
'parent_item_colon' => 'Parent Item:',
'new_item_name' => 'New Item Name',
'add_new_item' => 'Add New Item',
'edit_item' => 'Edit Item',
'update_item' => 'Update Item',
'separate_items_with_commas' => 'Separate items with commas',
'search_items' => 'Search Items',
'add_or_remove_items' => 'Add or remove items',
'choose_from_most_used' => 'Choose from the most used items',
'not_found' => 'Not Found',
);
$rewrite = array(
'slug' => 'work-items',
'with_front' => false,
'hierarchical' => true,
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
'rewrite' => $rewrite,
'query_var' => 'work-categories',
);
register_taxonomy( 'work-categories', 'our_work', $args );
}
add_action('init', 'create_taxonomies');
/**
* Add custom filters to replace categories in custom taxonomy paths
*/
add_filter('post_link', 'brand_permalink', 1, 3);
add_filter('post_type_link', 'brand_permalink', 1, 3);
function brand_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, '%work-categories%') === FALSE) return $permalink;
// Get post
$post = get_post($post_id);
if (!$post) return $permalink;
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, 'work-categories');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0]))
$taxonomy_slug = $terms[0]->slug;
else $taxonomy_slug = 'uncategorised';
return str_replace('%work-categories%', $taxonomy_slug, $permalink);
}
?>