2

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

get_header(), _e()

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

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.

0

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

  • That function is working quiet ok, problem is with template inclusion. I'm getting proper values for get_query_var('taxonomy') – sven Dec 29 '13 at 11:38
  • get_query_var() itslef uses $wp_query, I need not use $wp_query in my function. – sven Dec 29 '13 at 11:45

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.