Home › Forums › Backend Issues (wp-admin) › CPT Select Field, AJAX Update Another and Show in Admin? › Reply To: CPT Select Field, AJAX Update Another and Show in Admin?
I figured it out. Basically, in the AJAX response I iterated through each of the post ID’s of the Questions post type and added them to the select field of the post object ACF field as an <option>, which successfully populates the post object <ul>
visible to admins after the Exam post is published (in theory, you could also add a <li>
to the <ul>
for each question if you needed to display it to the admin, but I didn’t).
$.post(ajaxurl, examData, function(response) {
var questionSelect = $('select#acf-field_5c9b994d45a1a');
for(i=0; i<response.length; i++) {
var question_item = '<option value="'+response[i]+'" selected="selected" data-i="' + i + '">'+response[i]+'</option>';
questionSelect.append(question_item);
}
$('#publish').click(); //Save the Exam Post
console.log(response);
}, "json");
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.