I have a custom post type, Project:
/*******************************
Projects Custom Post Type
*******************************/
add_action( 'init', 'register_cpt_project' );
function register_cpt_project() {
$labels = array(
'name' => _x( 'Projects', 'project' ),
'singular_name' => _x( 'Project', 'project' ),
'add_new' => _x( 'Add New', 'project' ),
'add_new_item' => _x( 'Add New Project', 'project' ),
'edit_item' => _x( 'Edit Project', 'project' ),
'new_item' => _x( 'New Project', 'project' ),
'view_item' => _x( 'View Project', 'project' ),
'search_items' => _x( 'Search Projects', 'project' ),
'not_found' => _x( 'No projects found', 'project' ),
'not_found_in_trash' => _x( 'No projects found in Trash', 'project' ),
'parent_item_colon' => _x( 'Parent Project:', 'project' ),
'menu_name' => _x( 'Projects', 'project' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'excerpt' ),
'taxonomies' => array( 'project_categories' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
//'rewrite' => true,
'rewrite' => array('slug' => 'our-work/%project_categories%', 'with_front' => false),
'capability_type' => 'post'
);
register_post_type( 'project', $args );
}
And a Taxonomy, Project Categories:
/*******************************
Projects Category Taxonomy
*******************************/
add_action( 'init', 'register_taxonomy_project_categories' );
function register_taxonomy_project_categories() {
$labels = array(
'name' => _x( 'Project Categories', 'project_categories' ),
'singular_name' => _x( 'Project Category', 'project_categories' ),
'search_items' => _x( 'Search Project Categories', 'project_categories' ),
'popular_items' => _x( 'Popular Project Categories', 'project_categories' ),
'all_items' => _x( 'All Project Categories', 'project_categories' ),
'parent_item' => _x( 'Parent Project Category', 'project_categories' ),
'parent_item_colon' => _x( 'Parent Project Category:', 'project_categories' ),
'edit_item' => _x( 'Edit Project Category', 'project_categories' ),
'update_item' => _x( 'Update Project Category', 'project_categories' ),
'add_new_item' => _x( 'Add New Project Category', 'project_categories' ),
'new_item_name' => _x( 'New Project Category', 'project_categories' ),
'separate_items_with_commas' => _x( 'Separate project categories with commas', 'project_categories' ),
'add_or_remove_items' => _x( 'Add or remove project categories', 'project_categories' ),
'choose_from_most_used' => _x( 'Choose from the most used project categories', 'project_categories' ),
'menu_name' => _x( 'Project Categories', 'project_categories' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'show_admin_column' => false,
'hierarchical' => true,
//'rewrite' => true,
'rewrite' => array('slug' => 'our-work'),
'query_var' => true
);
register_taxonomy( 'project_categories', array('project'), $args );
}
add_action( 'init', 'register_cpt_leadership' );
In my Taxonomy archive template, I build out the URL to include the taxonomy term. So if "Project A" is in the "Awesome Stuff" category, the URL displays as:
[my domain]/our-work/awesome_stuff/project-a
All of this works perfectly on the front end. What doesn't work is when clicking buttons from the Admin side to view the project. If I'm editing "Project A", and click the View Project button under the permalink section, or the Preview Changes button on the right.
It returns a 400 Bad Request page, and sends the browser to:
[my domain]/our-work/%project_categories%/project-a
How can I make the preview/view buttons in the admin go to:
[my domain]/our-work/project_categories/project-a
That URL works, and since the preview links aren't tied to a specific Taxonomy, this would be the preferred solution.
EDIT: I'm unsure if I'm explaining this right. I do not need to alter the way permalinks are being handled across the site. All I need is a way to hook into any link in the admin section (the button pictured above, the preview button, and the View links on the list page). I need to just set the %project_categories% variable to "project_categories" if the link is generated via the admin.
'rewrite' => array('slug' => 'our-work', 'with_front' => false),