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:
<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
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;
I had this same problem. All you need to do is make sure you’re not returning the image as an object. You do this when creating/editing the custom field. Just make sure you set the return value to image url:
https://www.evernote.com/shard/s3/sh/91d181ed-e9d6-4504-8ab5-cee7ae85d84f/dfc9944d16337e41fb6e7e30ed26bdb5
Then, you should be able to use this to display the image in your template:
Have you set the customfield to return url. Looks lige it is set to object. You have 3 options to how to return an image.
Or you can just set custom field as IMAGE ID and use it like that