WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get the_ID() as variable (5 posts)

  1. schlobben
    Member
    Posted 8 years ago #

    I have searched over and over, so I finally gave up. Anyone know how to get the post id, using the_ID() without having it printed out?

    I need it to make a navigation where the active post is highlighted by comparing the post I am reading with the ID's of the posts in the menu.

  2. jaredquinn
    Member
    Posted 8 years ago #

    The global variable $id should have it.. all the_ID() does is:

    global $id;
    echo $id

  3. Lester Chan
    Member
    Posted 8 years ago #

    function get_the_id() {
    global $id;
    return $id;
    }

  4. schlobben
    Member
    Posted 8 years ago #

    Thank you for that ultra fast reply, and how easy can it be! This should be mentioned in the template tags next to the_ID(), guess it's more ppl than me that has been looking for it!

    $id was exactly what I needed!

    Thanks!

  5. $post->ID

    $post is an object which contains all data about a post directly from the database. There's also $comment.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags