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 developing a theme that has several custom taxonomy that act as radio buttons.

How do I write a conditional that does...

if(post_has_any_terms($post->id, 'custom-taxonomy')) { echo $term; }.

I feel like this should be so simple, but nothing that I have tried works.


share|improve this question

I ended up solving this. It might not be the smartest way but it works for me.

$terms = get_the_terms($post->ID, $taxonomy);
if(is_array($terms)) { 
        $term = array_shift(array_values($terms)); return $term; 
    } else { $term = "0"; }

The page doesn't work if $term = 0, but at least it lets the author know they forgot to check one of the boxes ( since it's required ).

share|improve this answer

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.