自定义发布类型重写引发发送的标头错误

时间:2011-07-25 作者:Evan Yeung

我用过Mixing custom post type and taxonomy rewrite structures?http://wordpress.org/support/topic/set-category-to-a-custom-post-type-automatically?replies=10 创建自定义帖子类型。但我的网站上已经收到一些发送错误的标题。特别是当我要保存页面或尝试登录时。

有人能检查一下代码以确保它是正确的吗。

// 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

1 个回复
最合适的回答,由SO网友:Jeff 整理而成

这发生在我的一个朋友正在开发的一个网站上。奇怪的是,他删除了有问题的文件,并将代码复制粘贴到新的php文件中。这似乎起到了作用。值得一试吗?

结束

相关推荐