Custom Post Type and Custom Taxonomy Permalinks

I’m currently working with a client’s WordPress blog that has a permalink structure set in the admin settings as “/speaks/%postname%/”. This is so that all actual blog posts (post_type=>posts) have the word “speaks” before them.

However, I have created a new custom post type and a new custom taxonomy for a new section on the site. I currently have a page at /advantages/professional-development that I would like to list the new custom taxonomy on as well as the new custom post types. I have code in place on this page that is listing out the custom taxonomy “categories” for my custom post type, but the permalink for each of these taxonomy terms include the word “speak” before the rest of the permalink.

How do I go about removing the word “speaks” only from this custom post type and taxonomy?

Here is the code creating my custom post type:

function register_custom_posts() {
register_post_type( 'profdev', /* (http://codex.wordpress.org/Function_Reference/register_post_type) */
        // let's now add all the options for this post type
        array('labels' => array(
            'name' => __('Professional Dev Posts'), /* This is the Title of the Group */
            'singular_name' => __('Professional Dev Post'), /* This is the individual type */
            'all_items' => __('All Professional Dev Posts'), /* the all items menu item */
            'add_new' => __('Add New'), /* The add new menu item */
            'add_new_item' => __('Add New Professional Dev Post'), /* Add New Display Title */
            'edit' => __( 'Edit' ), /* Edit Dialog */
            'edit_item' => __('Edit Professional Dev Posts'), /* Edit Display Title */
            'new_item' => __('New Professional Dev Post'), /* New Display Title */
            'view_item' => __('View Professional Dev Post'), /* View Display Title */
            'search_items' => __('Search Professional Dev Posts'), /* Search Custom Type Title */ 
            'not_found' =>  __('No Professional Dev Posts Found.'), /* This displays if there are no entries yet */ 
            'not_found_in_trash' => __('Nothing found in Trash'), /* This displays if there is nothing in the trash */
            'parent_item_colon' => ''
            ), /* end of arrays */
            'description' => __( 'Professional Dev Custom Post Type' ), /* Custom Type Description */
            'public' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => true,
            'show_ui' => true,
            'query_var' => true,
            'menu_position' => '', /* this is what order you want it to appear in on the left hand side menu */ 
            'menu_icon' => 'dashicons-businessman', /* 16px x 16px */
            'rewrite'   => array( 'slug' => 'advantages/professional-development', 'with_front' => false ), /* you can specify its url slug */
            'has_archive' => false, /* you can rename the slug here */
            'capability_type' => 'post',
            'hierarchical' => false,
            /* the next one is important, it tells what's enabled in the post editor */
            'supports' => array('title','editor','excerpt','page-attributes') // all of the post capabilities
        ) /* end of options */
); /* end of register post type */
} add_action( 'init', 'register_custom_posts');

And here is the code that creates my custom taxonomy for this post type:

function create_profdev_taxonomies() {
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
    'name'                       => _x( 'Categories', 'taxonomy general name' ),
    'singular_name'              => _x( 'Category', 'taxonomy singular name' ),
    'search_items'               => __( 'Search Categories' ),
    'popular_items'              => __( 'Popular Categories' ),
    'all_items'                  => __( 'All Categories' ),
    'parent_item'                => null,
    'parent_item_colon'          => null,
    'edit_item'                  => __( 'Edit Category' ),
    'update_item'                => __( 'Update Category' ),
    'add_new_item'               => __( 'Add New Category' ),
    'new_item_name'              => __( 'New Category Name' ),
    'separate_items_with_commas' => __( 'Separate categories with commas' ),
    'add_or_remove_items'        => __( 'Add or remove categories' ),
    'choose_from_most_used'      => __( 'Choose from the most used categories' ),
    'not_found'                  => __( 'No categories found.' ),
    'menu_name'                  => __( 'Categories' ),
);

$args = array(
    'hierarchical'          => false,
    'labels'                => $labels,
    'show_ui'               => true,
    'show_admin_column'     => true,
    'update_count_callback' => '_update_post_term_count',
    'query_var'             => true,
    'rewrite'               => array( 'slug' => 'advantages/professional-development/' ),
);

register_taxonomy( 'prof_dev_category', 'profdev', $args );
}

Ideally, I’d like to have the following permalink format: /advantages/professional-development/taxonomy-term/post-name

How can I go about achieving this?

Any help would be greatly appreciated!


UPDATE – Can’t believe I missed it, but somehow I forgot to include

, 'with_front' => false

at the end of my taxonomy rewrite slug rule. The corrected code is:

'rewrite' => array( 'slug' => 'advantages/professional-development', 'with_front' => false )

This results in ignoring the default permalink settings in WP Admin.

0

Leave a Comment