Support » Plugins and Hacks » What's wrong with custom fields and query posts?
7 years, 9 months ago
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”….
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
Ah-hah: the trick is to use $my_query->post->ID instead of $post->ID