Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a standard Wordpress loop displaying items:

     $loop = new WP_Query( array( 
            'post_type' => 'images',   
            'orderby' => 'menu_order',
             ) );

   while ( $loop->have_posts() ) : $loop->the_post(); 

   /* loop code, HTML mostly, a few if statements, nothing special */

   endwhile;

Now I want to display CERTAIN data from meta boxes and here comes the trouble.

the_meta() works just fine, but get_post_meta() doesn't work at all.

Why is this happening? Any fixes? I need to do something like get_post_meta($post->ID, 'metabox_field', true).

Any ideas?

[update]

Alright. More details.

I have a custom post type called "images".

Each image item has it's own metabox with a few fields inside, let's call them image_date, image_author, copyrights.

I want to display image author from field called image_author, so:

<?php 
    $author = get_post_meta($post->ID, 'image_author', true); 
    echo $author;
?>

The problem is it works ONLY when I open SINGLE image (single-image.php), but doesn't in loop (and I want to display this data for each item in loop also).

The_meta() works in both places if it changes something.

My loop looks exactly as above.

I guess that's all :)

share|improve this question
    
echo get_post_meta($post->ID, 'metabox_field', true); ? :) –  onetrickpony Mar 30 '11 at 17:34
    
I believe this works only inside items/pots but not with loops. At least not for me... :( –  Wordpressor Mar 30 '11 at 17:49
    
Doesn't work in what capacity? Would help a great deal if you could provide details of what you tried, what you expected to happen, what actually happened, etc.. "doesn't work" isn't really helpful in understanding the issue. –  t31os Mar 30 '11 at 17:58
    
@t31os, sorry, take a look at [update]. –  Wordpressor Mar 30 '11 at 18:10
1  
@WordPressor - What file(s) are you adding this loop code into? And also what URLs are you requesting when you expect to see these results? Additionally does every one of these posts have this meta field(definately)? –  t31os Mar 30 '11 at 18:14
show 2 more comments

1 Answer 1

up vote 0 down vote accepted

get_post_meta() function works In and Outside of the loop and you saying that you do see it working on a single image "but doesn't in loop" means that you probably did not add the code to the right loop.

To be clear It works with all posts types.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.