WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 created a simple function to display the latest posts. Inside the function there is a conditional to display the post category. I found that to display the category name, using

$category = get_the_category($post->post_ID); 

$category[0]->cat_name; // I want to display only the first category

do the job, but can't find how to display the link to the category. Tried to use get_category_link($post->post_ID) but no changes, the link still redirects to the current page. The goal is to redirect to category archive.

Appreciate any help.

share|improve this question
up vote 1 down vote accepted

If you can add your code, It may help for everyone. By reading you question. By default normally that get_category_link is have to work. Just use global $post before your loop. If is not work. What you have to do is.

  1. Grab the category id using your @category variable. (you can use print_r($category); or var_dump($category); after your code $category = get_the_category($post->post_ID);)

  2. Then use get_category_link(pass your grabbed category id)

I'm sure it will work.

For more info. Read this CODEX

share|improve this answer
I am happy. This is work for you. Please can you vote up. :-D – Big Bro Yesh Apr 16 '14 at 9:37

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.