New to WordPress, I've been trying to create an archive page for a custom post type, and when I click the link to localhost/websitename/wordpress/archive-event.php
I get a 404. Here is my code to register the post type:
add_action('init', 'event_register');
function event_register() {
$labels = array(
'name' => _x('Events', 'post type general name'),
'singular_name' => _x('Event', 'post type singular name'),
'add_new' => _x('Add New', 'event'),
'add_new_item' => __('Add New Event'),
'edit_item' => __('Edit Event'),
'new_item' => __('New Event'),
'view_item' => __('View Event'),
'search_items' => __('Search Events'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'event'),
'has_archive' => 'event',
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','thumbnail'),
);
register_post_type( 'event' , $args );
}
I've tried having rewrite => true
, has_archive => true
, flushing the rewrite rules, and even registering a taxonomy for the post type. single-event.php
works fine. What now?