WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using a custom URL on my menu to show the most viewed posts by passing the variables to the url as


However I want to use a custom template to display the results.

I tried the following but it doest work. I am having trouble finding a fix, can anyone help.

function custom_template($template) {
  global $wp;
  if ($wp->query_vars['template']=='basic') {
    return dirname( __FILE__ ) . '/basic.php';
  else {
    return $template;
add_filter('template_redirect', 'custom_template');
share|improve this question

You'll have to exit afterwards.

add_filter( 'template_redirect', 'wpse85164_query_var_template' );
function wpse85164_query_var_template( $template )
    if ( 'basic' === get_query_var( 'template' ) )
        exit( dirname( __FILE__ ).'/basic.php' );

    return $template;
share|improve this answer
Still not working :(( I cant seem to figure out whats wrong. – Jose David Garcia Llanos Feb 10 '13 at 16:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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