• Resolved doppyo

    (@doppyo)


    Hey WP gurus, here’s the problem that might get you a beer from me if you get to resolve it :

    My homepage has multiple loops. Within one of them, I’m sorting out five post from one category in a table. Next to the post’s title I want to get the post’s custom fields. Thing is, it seems impossible to get the current post’s id through $post->ID, in fact, the $post variable is empty so there’s no way I can get my custom field displayed. Here’s the code :

    <?php $my_query = new WP_Query('category_name=catname&showposts=5');?>
    ...some html...
    <?php while ($my_query->have_posts()) : $my_query->the_post();?>
    <tr>
    <td><?php the_title(); ?></td>
    <td><?php $key = "key1"; echo get_post_meta($post->ID,$key, true); ?></td>
    </tr>
    <?php endwhile; ?>

    I tried to print out the $post->ID and it is empty. I also tried to replace $post->ID in the code above with a random post’s id like get_post_meta(13,$key,true); and it works perfect so the problem here is getting the current post id properly. the_ID() works just fine but I can’t put its return value inside a $variable for some reason. Any help would be greatly appreciated.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Fields Problem’ is closed to new replies.