WordPress.org

Support

Support » Plugins and Hacks » [Resolved] What's wrong with custom fields and query posts?

[Resolved] What's wrong with custom fields and query posts?

  • Moderator Mark Ratledge

    @songdogtech

    Forum Moderator

    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”….

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Mark Ratledge

    @songdogtech

    Forum Moderator

    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

    Moderator Mark Ratledge

    @songdogtech

    Forum Moderator

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] What's wrong with custom fields and query posts?’ is closed to new replies.
Skip to toolbar