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 having trouble with conditional and custom post types.

i would like to set something up like this:

if (in_term('products')){
include ('products.php'); 
}elseif (in_term('downloads')){
include ('downloads.php'); 
}else {
    //Nothing Happens

Obviously this doesnt work, but if there is an alternative anybody knows then please share :)

Thank you,


share|improve this question
Not quite sure what you are looking for....? Your title asks about taxonomy, and your code idea hints at it, but you ask about a CPT? What are you trying to conditionalize for, and on? Maybe an edit just to clarify what you are trying to do? – Rev. Voodoo Sep 1 '11 at 14:44



if ( has_term('products', 'your_custom_taxonomy', $post ) ) 
elseif ( has_term( 'downloads', 'your_custom_taxonomy', $post ) )

Change your_custom_taxonomy to whatever that taxonomy name is. I changed include to get_template_part. If this is found in a theme file, that's the correct function to use. If it's in a plugin, feel free to change it back.

share|improve this answer
thank you for the response. i would like to know if its possible to pull in array of terms by the term parent? rather than manually typeing all terms. hope this makes sense? – Danyo Sep 1 '11 at 15:09
You're still going to have to check if the post has the term by typing it out if that's what you want. But you can get all the terms with either get_the_terms or the_terms: codex.wordpress.org/Function_Reference/get_the_terms & codex.wordpress.org/Function_Reference/the_terms – chrisguitarguy Sep 1 '11 at 15:45

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.