我用过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