WordPress.org

Forums

Category ID within the loop (4 posts)

  1. YellowSwordfish
    Member
    Posted 10 years ago #

    Can anyone tell me how I can determine the Category ID of the current post within the loop? or - if multiple categories, the ID of the final 'child' category?

    (Sorry - this is a re-posted question as I think it got lost before. Also many thanks to Kafkaesqui for help with a previous category question.)

    Thanks for any advice... I am impressed with the level of help so many members give.

  2. YellowSwordfish
    Member
    Posted 10 years ago #

    Nobody have any ideas or knowledge on this for 1.5.1 ? (Last time I try - honest!)

  3. davidchait
    Member
    Posted 10 years ago #

    did you try: get_the_category()

    gets an array of category objects, which you can loop over:
    $catlist = get_the_category();
    foreach ($catlist as $cat) echo $cat->cat_ID;

    I don't know which is the 'terminal' category, if they are sorted at all...

    -d

  4. YellowSwordfish
    Member
    Posted 10 years ago #

    David - thanks and sorry for time delay - got side-tracked!

    The old the_category_id was perfect for what I needed but is now deprecated. I will do some testing on your suggestion and perhaps work it out from there.

    Thanks again

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.