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 guess I need to know how to call meta data into metaboxes for beginners.

I'm using

$posts = get_posts(array(
        'post_type'   => 'slidertype',
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'fields' => 'ids'
        )
    );
    //loop over each post
    foreach($posts as $p){
        //get the meta you need form each post
        $thumb = get_post_meta($p,"_thumbnail_id",true);

        echo $thumb;

To try to get thumbnails of my custom post type 'slidertype' to show up in a page's metabox. Right now it's displaying a number which doesn't make sense to me. No advice is bad advice guys! Thanks.

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

You can get the image from your $thumb integer with the following additional code:

$thumb = get_post_meta($p,"_thumbnail_id",true);
$image = wp_get_attachment_image_src($thumb);
echo $image[0];

This will return the URL of the image, just put that in an img tag to display it.

share|improve this answer
    
Oh wow! I was so close but thanks so much. I'm trying to make a sortable list for my slider this way so I believe that I'll prob need the id's... Not sure. Thanks again. –  BenRacicot Sep 17 '12 at 21:38
add comment

You can also use get_the_post_thumbnail without having to first fetch the ID:

foreach( $posts as $p ){
    echo get_the_post_thumbnail( $p->ID, 'thumbnail' );
}

Or using setup_postdata you can use template tags that only work "in the loop":

foreach( $posts as $p ){
    setup_postdata( $p );
    the_post_thumbnail( 'large' );
}
wp_reset_postdata();
share|improve this answer
    
This is awesome. I wish I could vote you but I can't till lvl 15 sry. –  BenRacicot Sep 17 '12 at 21:40
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.