I created a plugin that adds a new post-type awards. Each award has multiple votes attached, which are stored in a custom table, created by the plugin.

Now I need to show two different overview-pages for the award:

  1. "mysite.com/awards" - show a list of all awards (simple)
  2. "mysite.com/votes" - show a list of all votes (problem)

The first part is simple: I create a theme file with the name "archive-award.php" and display the list.

I need help with the second case: A vote is not a custom post-type, so I cannot simply create an archive-votes.php file. This page has absolutely no relation to any item in the posts-table.

My idea is that I create a theme file (e.g. list-votes.php) and then link it with a custom slug. So the slug votes would open the theme file list-votes.php - but I could not find out how to do this.

Only solution which is not very good in my eyes is to create a page called votes and then add a short-code on that page which will display the list.

  • Are you looking for an endpoint?
    – fuxia
    May 31, 2013 at 10:21
  • Good point. I think I can solve this using an endpoint...
    – Philipp
    May 31, 2013 at 11:19
  • (ab)using page is actually quite common approach (and can be rather clean with dedicated template for it). Otherwise endpoint for more involved approach.
    – Rarst
    May 31, 2013 at 17:16

1 Answer 1


Thanks to toschos hint I could solve the problem. This is the code that I use:

// Register the endpoint
function my_init() {
    add_rewrite_endpoint('votes', EP_ALL);
add_action('init', 'my_init');

// Execute a function when the endpoint is called
function my_redirect() {
    global $wp_query;

    if (isset($wp_query->query_vars['votes'])) {
        $wp_query->is_404 = false;
        add_filter( 'wp_title', 'my_title_votes', 10, 2 );
        // this will output the template-file "all-votes.php"
        get_template_part( 'all-votes' );
        // Prevent WordPress from adding the front-page or 404 page to my output...
add_action( 'template_redirect', 'my_redirect' );

function my_title_votes( $title, $sep ) {
    return 'Votes-Title ' . $sep . ' ' .  $title;

When I open the URL mysite.com/votes/ I get my custom output, even though there is no page with that slug :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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