WordPress.org

Ready to get started?Download WordPress

Forums

get_the_category() is hit and miss when using sub-categories. (6 posts)

  1. Tom(dB)
    Member
    Posted 5 years ago #

    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.

  2. MichaelH
    Member
    Posted 5 years ago #

    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 http://wordpress.org/support/topic/212196 ]

  3. Tom(dB)
    Member
    Posted 5 years ago #

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

  4. MichaelH
    Member
    Posted 5 years ago #

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

  5. MichaelH
    Member
    Posted 5 years ago #

    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:
    http://trac.wordpress.org/ticket/7251

  6. Tom(dB)
    Member
    Posted 5 years ago #

    <?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.

Topic Closed

This topic has been closed to new replies.

About this Topic