Support

Account

Home Forums Front-end Issues Use Javascript API to set Post_Object Value Reply To: Use Javascript API to set Post_Object Value

  • So, I’ve run into similar issues with other field types in the past. For example, you can’t just set the value of an image field with the id and have the image appear. In that case I needed to do an AJAX request to get the image ID and the image URL for the correct size image after reading the image size attribute from the image field. Once I had this information I needed to set the image, set the url and also needed to add/remove classes in elements of the image field. Basically what I needed to do was to dig through the ACF code and figure out how ACF did it and then duplicate what it was doing.

    In this case your dealing with a post object field which uses select2 and this is likely complicating matters. Without spending a great amount of time digging through ACF JS code and actually trying to build this myself I wouldn’t be able to tell you exactly what you need to do.

    Going to be honest, in these cases I try to stick with basic field types that are easily manipulated, like the select field that you say works. It is usually not as pretty but it gets the job done.