Hello,
I created a front end form, whitch looks like this:
<?php
$new_post = array(
'post_id' => 'new',
'field_groups' => array(57),
'form' => true,
'return' => '%post_url%',
'html_before_fields' => '',
'html_after_fields' => '',
'submit_value' => 'Submit Post',
'updated_message' => 'Saved!'
);
acf_form( $new_post );
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
var ajaxUrl = "SITE_ADMIN_URL/admin-ajax.php";
$(".acf-button").on("click",function(){ // When btn is pressed.
var selected_model = $("#acf-field-area option:selected").text();
if(selected_model ){
$.post(ajaxUrl, {
action:"the_model",
selected_model: selected_model
});
}
});
});
</script>
In functions.php i have added the following function:
add_filter('acf/save_post', 'add_car_model', 20);
function add_car_model($post_id) {
$post_type = get_post_type($post_id);
if ($post_type != 'cars') {
// not our post type, bail early
return;
}
$selected_model = $_POST['selected_model'];
add_post_meta($post_id, 'car_model', '');
update_post_meta($post_id, 'car_model', $selected_model);
}
I have a select dropdown called Make, and based on the make, i am loading values into Model dropdown, which is custom dropdown.
Using javascript, i managed to get the correct model value(tested it using on change and alert();) but i do not know how to pass the model value into the post’s meta data.
Thank you for looking into this!