Support » Plugins » Hacks » taxonomy_exists to display alternate size featured image

  • Resolved iragless



    I have an archive page that displays a custom post types with a specific taxonomy. I’m trying to display a different featured image size if it has another specific sub taxonomy. I’m fairly new to wordpress and php so I could be taking the wrong approach. Basically the code I’m trying to use is

    <?php if (taxonomy_exists('spotlight')) {
             print "TRUE";
          else {
             print 'FALSE';

    At the moment it always returns false even on posts with that taxonomy.

    Not sure if it’s relevant but it is part of a child theme.

    Appreciate any assistance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    Hmm, something is not right, more than you know. taxonomy_exists() reflects the presence of a taxonomy in the DB AFAIK, not a particular post. So if ‘spotlight’ is properly registered, it should always return true, not false. You should investigate this further.

    As for checking if a taxonomy is assigned to a particular post, wp_get_post_terms() will do the job. It is meant for getting the actual terms more than checking for a taxonomy, but it does that as well. I’m not sure if there’s a simple template tag similar to taxonomy_exists() that checks a specific post.

    Welcome to WordPress, it can be aggravating, but it is also powerful and malleable. Good fun ahead 😉


    I figured that might be the case. Anyway I got it to work with wp_get_post_terms() and then using in_array to check for the required taxonomy. Basically this in case it helps someone else.

    $term_list = wp_get_post_terms($post->ID, $taxonomy, array("fields" => "names"));
          if (in_array('Spotlight', $term_list)) {
      stuff for that taxonomy;
              } else {
      something else;

    Not sure why taxonomy_exists() isn’t working? Might have a look later and see if I can work it out.


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘taxonomy_exists to display alternate size featured image’ is closed to new replies.