// 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' ),
)
);
}
For some reason when I create a new post it duplicates the same slug as the first post, so say the slug is forums=hello-world, the next post will automatically be forums=hello-world-2 no matter what the title is...
I have tested on fresh install several times and I get the same issue...
UPDATE: I have discovered that the problem is being caused by my custom metabox:
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
}