Support » Requests and Feedback » get_the_category() is hit and miss when using sub-categories.

  • There is a real issue with categories in WP.
    Basically I am listing posts by region. So I have ‘UK’ as top level, then Scotland, North East, North West, etc. as sub-categories.

    When categorising posts I tick ‘UK’ and ‘Scotland’. This sometimes works and ‘the_category()’ displays as ‘UK > Scotland’. However sometimes it will say ‘Scotland > UK’.
    Then when trying to use ‘get_the_category()’ of the archive page I am on it will return either ‘UK’, or ‘Scotland’ depending on how the posts in that archive have their category logged. So despite being on ‘Scotland’, ‘get_the_category()’ returns ‘UK’.

    There doesn’t appear to be a work around, and I think it’s a bug in WP that needs fixing urgently. Categorisation is an important part of a blog, and especially when attempting to use WP as a CMS.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I’m not seeing that with the WordPress Default theme.

    The index.php, archive.php, and single.php scripts in wp-content/themes/default use <?php the_category(', ') and I don’t see the results switched like you are experiencing.

    [edit just saw this thread so will try to dig deeper ]

    Thanks. I have noticed it in the past but it was never so critical as it is to me now.

    Can you post here the code you are using for the_category — just need a one line example.

    If I’m reading it correctly, the Template_Tags/template tag, the category(), is not meant to show categories in a true hierarchical (or breadcrumb) manner.

    You might try using the_category('->','mulitple') to see if you like that result.

    If necessary, please consider making at comment on this ticket:

    <?php the_category(' &raquo; ') ?> is the code I’m using.

    I don’t think how ‘the_category’ lists is the problem, as within the admin area the order of assigned categories shows a similar issue, i.e. they don’t always follow the ‘main-cat > sub-cat’ order.

    This generally isn’t too much of a problem, but my issue is that I’m selling adverts based on ‘archive.php’ category pages, and I return what category someone wants their advert on by detecting the current category (with ‘get_the_category’).

    My current workaround is to make everything a top level category. But when my listings extend outside the UK it could get a little messy.

    Thanks for your replies.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘get_the_category() is hit and miss when using sub-categories.’ is closed to new replies.