Derrick
Derrick

Reputation: 1

How to display selected category term in Wordpress?

I want to be able to display the selected category term for a custom post type. So, for example parent category is "Industry". Sub-categories are "Restaurants, Web Design, etc.". The Category selected is "Web Design". I need to display "Web Design" on the front end of my website to look like this "Industry - Web Design".

Upvotes: 0

Views: 1422

Answers (1)

erwstout
erwstout

Reputation: 1307

You'd want to try something like this:

<div class="yourelement">
    <p>Industry - <?php the_terms( $post->ID, 'industry');?> </p>
</div>

I just guessed that the slug for Industry is just industry, but you'll want to double check that.

The Terms Codex goes more into detail on how it functions and shows more options: https://codex.wordpress.org/Function_Reference/the_terms

Upvotes: 1

Related Questions