Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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?

share|improve this answer
    
Thanks that did the trick. –  imHavoc Jul 26 '11 at 15:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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