I used Mixing custom post type and taxonomy rewrite structures? and http://wordpress.org/support/topic/set-category-to-a-custom-post-type-automatically?replies=10 to create my custom post type. But I am getting some headers already sent errors on my site. Specifically when I go to save a page or try to log in.
Can somebody check the code to make sure it is correct.
// PROJECTS
add_action('init', 'create_work_projects');
function create_work_projects() {
register_taxonomy( 'project_category', array(), array(
'hierarchical' => true,
'labels' => array(
'name' => 'Categories',
'singular_name' => 'Category'
),
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'work' )
));
register_post_type( 'projects', array(
'labels' => array(
'name' => 'Projects',
'singular_name' => 'Project'
),
'supports' => array('title', 'editor', 'thumbnail'),
'public' => true,
'hierarchical' => false,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'rewrite' => array(
'slug' => 'work/%project_category%',
//'slug' => 'work',
'with_front' => false
),
'query_var' => true,
'has_archive' => 'work',
'taxonomies' => array( 'project_category' )
));
}
add_filter('post_type_link', 'work_project_permalink', 10, 4);
function work_project_permalink($post_link, $post, $leavename, $sample) {
if ( false !== strpos( $post_link, '%project_category%' ) ) {
$glossary_letter = get_the_terms( $post->ID, 'project_category' );
$post_link = str_replace( '%project_category%', array_pop( $glossary_letter )->slug, $post_link );
}
return $post_link;
}
add_action('publish_projects', 'projects_default_category');
function projects_default_category($post_ID) {
global $wpdb;
if(!has_term('', 'project_category', $post_ID)) {
wp_set_object_terms($post_ID, 'Uncategorized', 'project_category');
}
}
Wordpress 3.2.1