0

I am trying to get the custom taxonomy term for a single custom post type and seem to be falling flat. I thought the most obvious answer was to use single_term_title() but have tried just about every term related Wordpress function I could find in the codex but most of them seem to return arrays and I only want the term title for single-match.php Here is what I thought would work.

<?php $matchtype = single_term_title("", false); ?>

<h5><?php echo  $matchtype->slug . ' match' ?></h5>
  • 1
    I assume that single-match.php means that you are on a single view of your custom post type. Are you sure that WordPress runs a custom taxonomy query on this page? Could you run a var_dump( get_queried_object() );? – Fränk Jul 23 '13 at 9:21
  • Yes, single-match.php is a single view or the custom post type. You're right it doesn't look look like. Nothing resembling post category or post taxonomy. I suppose I should do a custom query then and then presumably I'll be able to use single_term_title() ? – mantis Jul 23 '13 at 12:44
  • It depends on what you are trying to do. If you have a single match (your CPT) and you want to display the type of match to which it is associated (your custom taxonomy), then you could use get_the_terms(): codex.wordpress.org/Function_Reference/get_the_terms The first code example should work. – Fränk Jul 24 '13 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.