taxonomy_template filter do not loads custom taxonomy template properly

I’m using taxonomy_template filter in my plugin to load a template file for custom user taxonomies. This is the code I’m using

 add_filter( 'taxonomy_template', 'get_custom_taxonomy_template' );
 function get_custom_taxonomy_template($template) {

   $taxonomy = get_query_var('taxonomy');

   if (strpos($taxonomy,'rcm_user_') !== false) {
      $taxonomy_template = UT_TEMPLATES_URL ."user-taxonomy-template.php";
      $file_headers = @get_headers($taxonomy_template);
      if( $file_headers[0] != 'HTTP/1.0 404 Not Found'){
         return $taxonomy_template;
      }
   }
   return $template; 
}

It loads the file but I get fatal error for wordpress functions like

Read More
get_header(), _e()

I’ve tried using default theme, saving permalink structures.

Related posts

2 comments

  1. Issue was with UT_TEMPLATES_URLused for including the template.

    I was using file URL and not file PATH which was creating the issue.

    Modifying the UT_TEMPLATES_URL, to FILE PATH fixes the issue.

  2. The get_query_var function requires the wp_query object, and it is not within your functions scope – so you need to include it:

    global $wp_query;
    

    This should work.

    Jørgen Juel

Comments are closed.