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.

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

1 Answer 1


This happened to a site a friend of mine was working on. Whats weird is that he deleted the problematic file and copied paste the code into a new php file. It seemed to do the trick. worth a shot?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.