WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] What's wrong with custom fields and query posts? (3 posts)

  1. Hello, My dog keeps asking me, "So what am I doing wrong with custom fields and query posts? " She really wants to get this to work.

    What she wants to do is show the contents of the custom field "qanda" of the most recent post in "posts." (Inside the loop, hence the wp_query).

    <?php $my_query = new WP_Query('category_name=posts&showposts=1'); ?><?php while ($my_query->have_posts()) : $my_query->the_post(); ?><?php echo get_post_meta($post->ID, "qanda", $single = true); ?><?php endwhile; ?>

    Blue says "thanks"....

  2. My dog tells me she tried hard coding a post number, such as:

    <?php echo get_post_meta('602', "qanda", $single = true); ?>

    and the value of the custom field "qanda" will echo. But the code won't take the post ID generated by the query loop.

    Any ideas for her? Thanks, Mark

  3. Ah-hah: the trick is to use $my_query->post->ID instead of $post->ID

Topic Closed

This topic has been closed to new replies.

About this Topic