• Hi,
    I’m trying to list all the current pages Sub pages.
    each of those pages has a custom field – “Description”
    no prizes for what i’m going to put in that field!

    heres my code:

    <?php $page_query = new WP_Query('post_type=page&post_parent=19'); ?>
    <?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
    <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
    <?php $meta_desc = get_post_meta(the_ID(), 'Description', true); echo $meta_desc; ?>
    <?php endwhile; ?>

    so far, it lists the pages, and displays the titles.
    where the description should be is just the id of that page, for example “42”
    I know that its expected, as im using the_ID() incorrectly.
    So, i tested it by putting ’42’ in place of the_ID() which works fine.

    My question, how do i get the id of the current post in the loop?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The Template_Tags/the_ID displays the ID but doesn’t return it for use in another function or variable.

    So try:
    $post->ID
    or
    $page_query->post->ID

    The the_ID() function only echos the current post id. So I found that function in the code and replicated it in my plugin. The original function is:

    “get_the_ID()” actually returns it

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get id of post in loop…?’ is closed to new replies.