Why reinvent the wheel? Just create archive-{posttype}.php
, and ensure that 'has_archive'
is set to true
for the post type.
If your post type is event
: archive-event.php
.
Then, WordPress will handle the query automatically. If pretty permalinks are enabled:
example.com/{posttype}
…will display the archive index page for {posttype}
.