WordPress.org

Support

Support » Plugins and Hacks » Get post ID for use in PHP

Get post ID for use in PHP

  • 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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • did you try $post->ID?

    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get post ID for use in PHP’ is closed to new replies.
Skip to toolbar