Support

Account

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");