• Resolved primestyle

    (@primestyle)


    Hi I am currently using this:

    <ul><?php $recent = new WP_Query("cat=1&showposts=5"); while($recent->have_posts()) : $recent->the_post();?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php $key="jeu"; echo get_post_meta($post_id, $key, true); ?></li>
    <?php endwhile; ?>

    If i replace $post_id by a number it works. But I want to be able to add the post ID in $post_id automaticly so I donth ave to do it manualy. I’ve tried $post_id=the_id(); but that doesnt work it only shows the ID instead of getting the value of my custom field.

    any help would be great, thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Try $id or $post->ID — both should be available in the post loop.

    Thread Starter primestyle

    (@primestyle)

    yeah i tried that too, but I’m going to use it outsite of the loop in the side bar.

    The good news is I found a way, and this could come very handy in many occations using op_star()

    heres how I did it

    <?php
    ob_start();
    the_ID();
    $post_id = ob_get_contents();
    ob_end_clean();
    ?>
    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Yikes. That’s a really roundabout way of doing things.

    Try this instead:
    $post_id = get_the_ID();

    Might be simpler and it won’t break things like the ob_start stuff will.

    For most all Loop functions, when you need values returned to you as a variable or a number, use get_the_whatever. When you just want to display the value of the variable, you use the_whatever. This is the general WordPress convention.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘give $post_id a value’ is closed to new replies.