7

I'm trying to dynamically load images from a certain post type. I've used the Advanced Custom Fields plugin to attach an image field to my post. I'm currently using this code:

$.getJSON('/?json=get_recent_posts&post_type=slides-verhuur&custom_fields=image', {}, function(data){
    console.log(data);
});

However when I run the code, the result JSON I get contains a "custom field" attribute, which have an "image" attribute, but this only contains the value of "80", which is the ID of the image. Is there a way to get the image url instead?

2 Answers 2

1


You need to set Return Value as "Image URL" instead of "Image ID" Under Custom Fields group a image field as per image shown below.

enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

hi, this stills return the photo ID even though it is set to Image URL. I am guessing because of the theme or some custom functions ACF fails to get the URL and returns ID
Running into the same issue, even tried re-adding the images but didn't work out.
Have you manually added the custom field to the JSON? If so what code did you use?
Guys, any idea how to fix it?
Here's a helpful post from developers of the ACF plugin: support.advancedcustomfields.com/forums/topic/… Basically just adding ?acf_format=standard to your request URL returns the image URL.
0

$post_response->data['CFS'] = CFS()->get(false, $page->ID, array('format' => 'api'));

use 'api' instead of 'raw'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.