Wondering if anyone has an example of how set the value of the relationship field with jquery?
What we are trying to do is create a template relationship field and allow users to choose a template to populate that posts relationship filed.
I was able to do it via post save using the Post Object to select the post that has the relationship template. However, it would be really nice to pass the postID array via jquery without having to refresh the page.
I have examples of setting fields using jQuery, but I have not done a relationship field. I did do this for a date field recently for another post. This had to do with interacting with the jQuery datepicker itself as apposed to interacting directly with the ACF field. I’m guessing that a relationship field would be similar due to the fact that you’re dealing with a select2 field and would probably need to interact directly with setting the value by calling some select2 function.
Anyway, the example for the datepicker field is here https://support.advancedcustomfields.com/forums/topic/autocomplete-end-date-when-start-date-is-selected-in-jquery-date-picker/
and my other examples are here, they might help. https://github.com/Hube2/acf-dynamic-ajax-select-example
Thank you so much for the reply!
I will see what I can figure out your examples are great!