• Snuk

    (@snuk)


    Hi,

    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?

    Thanks in advance.

    – Leon

    https://www.ads-software.com/plugins/json-api/

Viewing 1 replies (of 1 total)
  • jpvanmuijen

    (@jpvanmuijen)

    The value you get is an attachment id, which refers to the attachment array.
    “image”:[“80”] => “attachments”:[{“id”:80,”url”:”blabla”

    However, I have a similar problem when getting multiple posts; only one of the posts contains attachments. Using &include=attachments in the request does show the attachments, but causes all other fields to disappear.

    Anyone else any thoughts on that?

Viewing 1 replies (of 1 total)
  • The topic ‘Getting an image from a custom field’ is closed to new replies.