0

I've created a plugin which registers a custom post type and a custom taxonomy for me. Now, whenever I visit: www.mysite.com/events_categories/category I should get a list of all the posts under that category. I want to use my own template and not Wordpress' default category template. Also, I want this template to be used for ALL categories, not just one category.

I used this code:

function taxonomy_template() {
    global $post;

    if( is_tax( 'event_categories' ) ) {
        $tax_tpl = dirname( __FILE__ ) . '\taxonomy-event_categories.php';
    }
    return $tax_tpl;

}
add_filter( 'template_include', 'taxonomy_template' );

And while it works for the taxonomy, it makes everything else on the site go blank. This is because the $tax_tpl is empty if the page I'm on isn't a taxonomy. I've tried using template_redirect, but no luck either.

So I want to know how to hook my template (taxonomy-event_categories.php) to the Wordpress' category template.

Hope you guys have a solution, because I've looked everywhere and it's possible to find the solution, yet I see many plugins doing this effortlessly.

Stefan
  • 218
  • 1
  • 4
  • 13

1 Answers1

1

Okay, so I solved it using this code:

add_action('template_redirect', 'taxonomy_template');
function taxonomy_template( ){
    $tax_tpl = dirname( __FILE__ ) . '\taxonomy-event_categories.php';
    if( is_tax('event_categories') ) {
        include $tax_tpl;
        die();
    }
}

I've no idea why this works because I think I already tried this specific code, but it didn't work. Let's just hope it will keep working.

Stefan
  • 218
  • 1
  • 4
  • 13