"Image Advanced" field doesn't save full image details to REST API

Support MB REST API "Image Advanced" field doesn't save full image details to REST APIResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #19313
    LucienLucien
    Participant

    When I look up my "Image Advanced" field data via REST API, I only get the image ID (as if "Image Advanced" was a regular "Image" field). Looks like this:

    "image_url":["3344"]

    I'm not getting the full "Image Advanced" image data (like image URL).

    #19314
    LucienLucien
    Participant

    It seems like this error only occurs when the "Image Advanced" field is put inside a Group.

    #19324
    Long NguyenLong Nguyen
    Moderator

    Hi,

    If the field is nested in a group, it will be serialized and saved in the database such as {"image_advanced":["1957","1956","1955"]}. For some special fields, only the ID will be saved and you need to use some helper functions to get the URL of the image by the ID. For more information, please follow this documentation
    https://docs.metabox.io/extensions/meta-box-group/#special-fields

    #19325
    Anh TranAnh Tran
    Keymaster

    Hi Amanda,

    That's right. For groups, the data is sent as raw, similarly to what you get via the helper function.

    #19346
    LucienLucien
    Participant

    Got it! Why is it set up this way? I need to make a ton of calls to the REST API to grab metabox data, including image URLs, so I can display the content elsewhere (not on wordpress). I want to avoid making all those extra calls to the REST API (to /wp-json/wp/v2/media/{id}) to fetch the full image URLs. Is there a way I can edit one of the metabox plugins to add the full url field to Image Advanced (whether it's nested in a group or not)? Or is there no way to make this work when Image Advanced is nested in a group?

    #19353
    Long NguyenLong Nguyen
    Moderator

    Hi,

    It's the feature of Group field Database optimization of sub-fields for reduced bloat. If every field nested in Group has all property saved, it will increase the size of the database and slow down your site. That's why Group only saves necessary information of the sub-field.

    Hope that makes sense.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.