Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

http://website.com/?v_sortby=views&v_orderby=desc

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.