0

I'm trying to do a template redirect in my wordpress but with partial success

  function ahaali_qa_theme_redirect(){
    global $wp;
    $plugindir = dirname(__FILE__);

    if(is_archive()){
        $tname = 'archive-question.php';
        if(file_exists(TEMPLATEPATH.'/'.$tname)){
            $returntemplate = TEMPLATEPATH.'/'.$tname;
        }else{
            $returntemplate = $plugindir.'/default-template/'.$tname;
        }
        ahaali_do_theme_redirect($returntemplate);
    }elseif(is_single()){
        $tname = 'single-question.php';
        if(file_exists(TEMPLATEPATH.'/'.$tname)){
            $returntemplate = TEMPLATEPATH.'/'.$tname;
        }else{
            $returntemplate = $plugindir.'/default-template/'.$tname;
        }
        ahaali_do_theme_redirect($returntemplate);
    }elseif(is_archive() && is_tax('question_category')){
        $tname = 'taxonomy-question_category.php';
        if(file_exists(TEMPLATEPATH.'/'.$tname)){
            $returntemplate = TEMPLATEPATH.'/'.$tname;
        }else{
            $returntemplate = $plugindir.'/default-template/'.$tname;
        }
        ahaali_do_theme_redirect($returntemplate);
    }
}

everything works except the is_tax() , can somebody explain me how to do this or what I'm doing wrong ?

Thank you !

1 Answer 1

0

this is just a simple php syntax issue- anything that meets the conditions is_archive() && is_tax('question_category') will also return true for the first if(is_archive()), so you're code is never reaching that test.

2
  • Also, is_tax() is deprecated as of 3.0. You should be using taxonomy_exists() instead. Commented Jun 16, 2012 at 13:53
  • is_tax() is not deprecated. What is deprecated is is_taxonomy() (in fact, you've actually linked to this function). Commented Jul 2, 2013 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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