WordPress.org

Ready to get started?Download WordPress

Forums

Get post ID for use in PHP (3 posts)

  1. CounterDax
    Member
    Posted 8 years ago #

    Hi All!

    I've got most coding for my little hack done, but I am unable to retrieve the post ID for use in PHP. For a hack I am macking I really need to be able to parse the post ID as a variable.
    I am using the following to get the post:

    <?php
    $posts = get_posts('numberposts=1&offset=X')
    foreach($posts as $post) :
    setup_postdata($post); ?>

    Is there some way I can get the post ID? The_ID echoes the ID number, but I need to use it as a variable. I am unable to find anything in the support forum or the codex. Any help would really be appreaciated!
    Thanks in advance!

  2. davidchait
    Member
    Posted 8 years ago #

    did you try $post->ID?

  3. CounterDax
    Member
    Posted 8 years ago #

    Oh God, I'm so stupid! I checked my code and I never noticed I accidentaly wrote $post=>ID (notice the equals sign).
    Now I've been spamming the support forum because I was an idiot. Sorry and thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic