Support » Plugins and Hacks » get_the_category outside the loop

  • Resolved snakerboy

    (@snakerboy)


    I would like to use get_the_category function outside of the loop. Anyone got ideas how I might do this?

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 ‘get_the_category outside the loop’ is closed to new replies.