WordPress.org

Support

Support » Plugins and Hacks » [Resolved] get_the_category outside the loop

[Resolved] get_the_category outside the loop

Viewing 2 replies - 1 through 2 (of 2 total)
  • get_the_category() expects to be called from within The Loop. To use this tag outside the loop, you’ll need to make a global post object named $post that contains the data of the post you want.

    <?php
    $id = 15; // which post ID to use
    $post= get_post($id); // fetch that post
    $cats = get_the_category();
    ?>

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] get_the_category outside the loop’ is closed to new replies.