WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

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' );
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

Your Answer


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.