Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8482091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:44:08+00:00 2026-06-10T19:44:08+00:00

I am trying to show the category name in a wordpress loop for the

  • 0

I am trying to show the category name in a wordpress loop for the category page of a custom taxonomy and I have done many searches for an answer and I have not been able to find it or I am doing something wrong. I am trying to show only 1 term. The categories have sub categories and another level of subcategories as well.

So I need the term to dynamically reflect the term of page that is being viewed. I have this code that works but it displays the whole list of terms associated with the post and since the post has parent, child, and granchild terms, I don’t want it to show all the terms at once.

<?php $terms = wp_get_post_terms( $post->ID, 'videoscategory');

echo '<h2>';

foreach ($terms as $term) {

echo '<a href="'.get_term_link($term->slug, 'videoscategory').'">'.$term->name.'</a>';

}

echo '</h2>'; ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:44:10+00:00Added an answer on June 10, 2026 at 7:44 pm

    This has to do with the foreach, which is looping through every term. A quick and dirty way to do it is to insert <?php break; ?> before the endfor

    See this thread for more: How to get only one result from foreach(PHP)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to call $this->getIsAnchor() from a category template file to show certain
I have several TableLayoutPanels, each of which displays a category of name/value information in
I'm trying to show only 5 reviews from a specific category as opposed to
In Magento, I'm trying to show a phtml a custom module in list.phtml. My
I have this category on my wordpress: Test1 - Sub1OfTest1 - Sub2OfTest1 Test2 -
I am trying to make a second page show up via a BroadcastReceiver, but
Trying to show a label only when a certain item in a combo is
I'm trying to show/hide( or simply put - filter ) my markers( of houses
I'm trying to show a UIAlertView before actually deleting a cell from a UITableView
I'm trying to show a div when a user clicks in an input field,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.