Advanced Custom field thumbnail – wordpress

I’m working on a website in wordpress, i’m trying to get the thumbnail from the advanced custom field of a post with this:

<?php while ( have_posts() ) : the_post(); ?>
    <h1><?php the_field('custom_title'); ?></h1>
    <img src="<?php the_field('thumbnail'); ?>" alt="" />
    <p><?php the_content(); ?></p>
<?php endwhile; // end of the loop. ?>

The problem it’s that when I load the website, the url the image gets looks like this:

Read More
<img src="5, , item_alt2, , , http://portfolio.local/wp-content/uploads/2012/09/item_alt2.jpg, Array">

So, as far as I see, the plugin it’s working since looks for the image, but it loads an strange path to it, so it shows like “broken” image.

What i’m doing wrong?

 5, , item_alt2, , , http://portfolio.local/wp-content/uploads/2012/09/item_alt2.jpg, ArrayNULL

Related posts

Leave a Reply

4 comments

  1. Have a look at the docs on Advanced Custom Fields;

    http://www.advancedcustomfields.com/docs/field-types/image/

    You are returning the value of the custom field as an object as per the example at the bottom;

    Array
    (
    [id] => 540
    [alt] => A Movie
    [title] => Movie Poster: UP
    [caption] => sweet image
    [description] => a man and a baloon
    [url] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
    [sizes] => Array
        (
            [thumbnail] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-150x150.jpg
            [medium] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-300x119.jpg
            [large] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
            [post-thumbnail] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
            [large-feature] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
            [small-feature] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-500x199.jpg
        )
    
    )
    
  2. Or you can just set custom field as IMAGE ID and use it like that

    $image = wp_get_attachment_image_src(get_field('thumbnail'), 'sizename');
        <h1><?php the_field('custom_title'); ?></h1>
        <img src="' .$image[0]. '" alt="">
        <p><?php the_content(); ?></p>
    <?php endwhile; // end of the loop. ?>