i'm making a plugin for wordpress and i have a custom post-type, when i install this plugin into a new site and i create a post inside this new post type i have a 404 error. if i go to setting->permalinks-> and click on save. the problem is fix. but, i dont want to do it mannualy i want that my plugin do this for me. so i was looking on the internet and everybody says that i have to use the rewrite fuction. but its not working for me...here is my code.
<?php
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
// Creating the post type
function eleva_sponsors_custom_post_type() {
$singular_sponsors = "Sponsor";
$plural_sponsors = "Sponsors";
$labels_sponsors = array(
"name" => $plural_sponsors,
"singular_name" => $singular_sponsors,
"add_new" => "Add New",
"add_new_item" => "Add New " . $singular_sponsors,
"edit_item" => "Edit " . $singular_sponsors,
"new_item" => "New " . $singular_sponsors,
"view_item" => "View " . $singular_sponsors,
"search_items" => "Search " . $plural_sponsors,
"not_found" => "No " . $plural_sponsors." found",
"not_found_in_trash" => "No " .$plural_sponsors." found in trash",
"all_items" => "All sponsors"
);
$args_sponsors = array(
"labels" => $labels_sponsors,
"public" => true,
"publicity queryable" => true,
"show_in_nav_menus" => true,
"show_ui" => true,
"show_in_menu" => true,
"show_in_admin_bar" => true,
"menu_position" => 10,
"menu_icon" => "dashicons-format-gallery",
"can_export" => true,
"delete_with_user" => false,
"hierarchical" => false,
"has_archive" => true,
"query_bar" => true,
"capability_type" => "post",
"map_meta_cap" => true,
// capabilities => array()
"rewrite" => array(
"slug" => "sponsors",
"whit_front" => true,
"pages" => true,
"feeds" => true,
),
"supports" => array("title","thumbnail")
);
register_post_type("sponsors",$args_sponsors);
}
add_action( 'init', 'eleva_sponsors_custom_post_type' );
function custom_flush_rules(){
//defines the post type so the rules can be flushed.
eleva_sponsors_custom_post_type();
//and flush the rules.
flush_rewrite_rules();
}
register_activation_hook(__FILE__, 'custom_flush_rules');
?>
Try this code.