WordPress.org

Support

Support » How-To and Troubleshooting » get_the_category pulling wrong cat

get_the_category pulling wrong cat

  • I have a series of posts that are categorized under category ‘2005’ and sub-category ‘1:12’.

    I’m pulling the name of the parent category (2005) into the sidebar of each post using

    <? $category = get_the_category(); echo $category[0]->cat_name; ?>

    The problem is that it’s showing the sub-category (1:12) instead of the category (2005).

    I’m also pulling the sub-category name in another part using
    <? $category = get_the_category(); echo $category[1]->cat_name; ?>

    And that’s adding the parent instead of the sub.

    The problems seems to be that the sub-category is labeled using a numbers instead of letters. For instance if I change the sub cat name to ‘one : twelve’ it works properly.

    Anyone know how to fix this?
    Thanks much for any feedback!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_the_category pulling wrong cat’ is closed to new replies.