Home › Forums › Backend Issues (wp-admin) › jQuery Select2 Controls › Reply To: jQuery Select2 Controls
I changed the field type to post_object with multiple values enabled for aesthetic reasons. A lot of trial and error and digging found that this works to dynamically change the selected values…
var selector = '#acf-field_5f1f49df49567-field_5f33ff4c31a81';
$(selector)
.empty() //empty select
.append($("<option/>") //add option tag in select
.val("2514335") //set value for option to post it
.text("Red")) //set a text for show in select
.append($("<option/>") //add option tag in select
.val("2514356") //set value for option to post it
.text("Blue")) //set a text for show in select
.val(["2514335","2514356"]) //select option of select2
.trigger("change"); //apply to select2
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.