get_the_category pulling wrong cat (3 posts)

  1. brockman.eric
    Posted 3 years ago #

    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!

  2. Michael
    Forum Moderator
    Posted 3 years ago #

    get_the_category() is showing categories in alphabetical order - not by hierarchy; therefore showing the 'first' category can seem to be quite random.


    there is no general easy fix.

  3. brockman.eric
    Posted 3 years ago #

    hmmm, is there a way to call them by hierarchy, but only show the 'first' category, that you know of?


Topic Closed

This topic has been closed to new replies.

About this Topic