Retrieving ID from query_posts()
-
I’m running query posts to get the posts for a specific category, it’s working fine, but I also need to know the ID of the current post iteration so that I can pull a custom value for the particular post that I’m on.
When I try using $post->ID it returns the post id for the page that I’m on, not the one from my query_posts() loop. I’ve also tried using get_queried_object_id(), but that just throws up an error saying it’s an unrecognized function.
Here’s my code:
<?php query_posts('category_name=upcoming-events&showposts=10'); ?> <?php while (have_posts()) : the_post(); ?> <div class="module_row"> <h4><?php the_title(); ?></h4> <h5><?php get_post_meta(30, 'upcoming_event_date', true); ?> test</h5> <div class="hr"><hr /></div> </div> <?php the_content(); ?> <?php edit_post_link('Edit This Post', '<p class="right">', '</p>'); ?> <?php endwhile; ?>
In the get_post_meta() function, you’ll see, I need the ID field to be dynamic, not hard coded in.
Actually, this problem may extend beyond being unable to retrieve the ID. Even with it hard coded in as you see above
get_post_meta(30, 'upcoming_event_date', true);
It still doesn’t display the custom field I’m trying to pull out “upcoming_event_date”, and I’m positive that’s the correct ID too.I’m at a loss, any help would be greatly appreciated. Thanks!
- The topic ‘Retrieving ID from query_posts()’ is closed to new replies.