1

I have a custom content type called events that I register using the following function:

add_action('init', 'events_post_init');

function events_post_init() {
   register_post_type( 'events',
      array(
         'labels' => array(
            'name' => 'Events',
            'singular_name' => 'Event',
            'add_new' => 'Create new',
            'add_new_item' => 'Create new event',
            'all_items' => 'All events',
            'view_item' => 'View event',
            'search_items' => 'Search events',
            'not_found' => 'No events found',
            'not_found_in_trash' => 'No events found in trash',
            'menu_name' => 'Events',
        ),
        'rewrite' => array(
            array('slug' => 'events')
        ),
        'public' => true,
        'has_archive' => true,
        'show_ui' => true,
        'menu_position' => 6,
        'supports' => array('thumbnail', 'editor', 'title', 'excerpt'),
    )
  );
}

Now I would like to add a page that will be used to display an archive of events when I'm visiting /events/, so I have created a new template named page-events.php and then added a new page called Event Archive with a slug equal to events and under Page Attribute I have choose the new template I just created.
The thing is that the template is not being used when I go to the specified url. However if I remove the call to register_post_type() then it gets loaded?

1

Set has_archive to false in your arguments when registering your post type, flush your permalinks and you should be goog to go.

EDIT

has_archive

(boolean or string) (optional) Enables post type archives. Will use $post_type as archive slug by default.

Default: false

  • Thank you so much, this solved everything. One more reason to really read the documentation =) +1 – Cyclonecode Sep 22 '15 at 13:04
  • My pleasure, glad it worked out. Enjoy :-) – Pieter Goosen Sep 22 '15 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.