• Resolved davejay42

    (@davejay42)


    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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • I am also trying to figure out how to generate a list of IDs dynamically.

    Instead of hardcoding the IDs into the page template, I need code that will dynamically return an array of the IDs of categories that are currently children of a certain parent category.

    something like get_category_IDs(child_of=’ParentID’)?

    If you figure this one out, please let me know!

    c.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    @davejay42: $current_id = get_the_ID();

    Thread Starter davejay42

    (@davejay42)

    @otto42: Thanks a ton! That worked.

    For the record, here’s what I’m using now that works.
    echo get_post_meta(get_the_ID(), 'upcoming_event_date', true);

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Retrieving ID from query_posts()’ is closed to new replies.