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

i would like to set something up like this:

<?php 
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,

Dan

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

1 Answer

http://codex.wordpress.org/Function_Reference/has_term

So...

<?php 
if ( has_term('products', 'your_custom_taxonomy', $post ) ) 
{
    get_template_part('products'); 
}
elseif ( has_term( 'downloads', 'your_custom_taxonomy', $post ) )
{
    get_template_part('downloads'); 
}
?>

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
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.