• Resolved cmsnext

    (@cmsnext)


    Hi

    I am trying to get the last child category of a post

    For example here is my category

    Main Category
    > Child Cat
    >> Child of Child Cat
    >>>>Child of Child of Child Cat

    Now whenever I try to get the post child cat
    the_category("", "single", $post->ID)

    it only returns Child of Child Cat. Its not returning the last category.

    I tried various other methods too found on the web, but each time the max access I get is up to Child of Child Cat.

    Could anyone suggest a good code to grab the last child category id of a post in this case >>>>Child of Child of Child Cat

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try this:

    <?php
    $category = get_the_category($post->ID);
    echo end($category)->cat_name;
    ?>

    This will echo the last child category.

    Thread Starter cmsnext

    (@cmsnext)

    Thank you for your solution
    But this also returns one point above. Its not returning the Child of Child of Child Cat ID.

    With your solution too it returns >> Child of Child Cat ID

    Any suggestions?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Last Child Category of Post’ is closed to new replies.