Support » Fixing WordPress » Get post category outside the loop

  • Resolved tipone


    Boys and girls. i can not find the solution of this:
    I am writing a function in functions.php to show all post titles depending on opened post.
    F.e If the post belongs to category Books and there is another posts within this category – show those post titles.

    The trick bhind this is – the function is outside the loop. I am trying to get the active category Id, but it always returns last created category Id
    $categories = get_the_category();
    $category = $categories[0];
    $cat_id = $category->cat_ID;
    echo $cat_id;

    Do you know, how to return the category id outside the loop when reading a post?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get post category outside the loop’ is closed to new replies.