// register custom post type forums
function fp_forum_post_type() {
// set up labels
$labels = array(
\'name\' => \'Forums\',
\'singular_name\' => \'Forum\',
\'add_new\' => \'Add New Forum\',
\'add_new_item\' => \'Add New Forum\',
\'edit_item\' => \'Edit Forum\',
\'new_item\' => \'New Forum\',
\'all_items\' => \'All Forums\',
\'view_item\' => \'View Forum\',
\'search_items\' => \'Search Forums\',
\'not_found\' => \'No Forums Found\',
\'not_found_in_trash\' => \'No Forums found in Trash\',
\'parent_item_colon\' => \'Category:\',
\'menu_name\' => \'Forums\',
);
//register post type
register_post_type( \'forums\', array(
\'labels\' => $labels,
\'has_archive\' => true,
\'public\' => true,
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'thumbnail\',\'page-attributes\' ),
\'exclude_from_search\' => false,
\'capability_type\' => \'post\',
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'forums\' ),
)
);
}
由于某种原因,当我创建一篇新帖子时,它会复制与第一篇帖子相同的slug,所以如果slug是forums=hello world,那么无论标题是什么,下一篇帖子都会自动是forums=hello-world-2。。。
我已经在fresh install上测试了好几次,我也遇到了同样的问题。。。
更新:我发现问题是由我的自定义元数据库引起的:
function add_forum_attributes_metabox(){
add_meta_box(
\'forum_attributes\',
__(\'Forum Attributes\', \'forumpress\'),
\'forum_attributes\',
\'forums\',
\'side\',
\'high\',
array( \'id\' => \'forum_attributes\')
);
}
function save_forum_attributes_metabox($post_id, $post){
// Don\'t wanna save this now, right?
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return;
if ( !isset( $_POST[\'forum_attributes_nonce\'] ) )
return;
if ( !wp_verify_nonce( $_POST[\'forum_attributes_nonce\'], \'forumpress/includes/metaboxes/metaboxes.php\' ) )
return;
// We do want to save? Ok!
$key = \'forum_type\';
$value = $_POST["forum_type"];
if ( get_post_meta( $post->ID, $key, FALSE ) ) { // If the custom field already has a value
update_post_meta( $post->ID, $key, $value );
} else { // If the custom field doesn\'t have a value
add_post_meta( $post->ID, $key, $value );
}
if ( !$value ) delete_post_meta( $post->ID, $key ); // Delete if blank
$key = \'forum_category\';
$value = $_POST["forum_category"];
if ( get_post_meta( $post->ID, $key, FALSE ) ) { // If the custom field already has a value
update_post_meta( $post->ID, $key, $value );
} else { // If the custom field doesn\'t have a value
add_post_meta( $post->ID, $key, $value );
}
if ( !$value ) delete_post_meta( $post->ID, $key ); // Delete if blank
$key = \'forum_status\';
$value = $_POST["forum_status"];
if ( get_post_meta( $post->ID, $key, FALSE ) ) { // If the custom field already has a value
update_post_meta( $post->ID, $key, $value );
} else { // If the custom field doesn\'t have a value
add_post_meta( $post->ID, $key, $value );
}
if ( !$value ) delete_post_meta( $post->ID, $key ); // Delete if blank
$key = \'forum_order\';
$value = $_POST["forum_order"];
if ( get_post_meta( $post->ID, $key, FALSE ) ) { // If the custom field already has a value
update_post_meta( $post->ID, $key, $value );
} else { // If the custom field doesn\'t have a value
add_post_meta( $post->ID, $key, $value );
}
if ( !$value ) add_post_meta( $post->ID, $key, \'0\' ); // add 0 if blank
}