Query data after an Ajax insert
After a successful insertion with Ajax of an entry I would like to see what the ID and url of that same entry is and show it in a modal window
Any way to get that data?
script
ajax_url = ?php echo admin_url('admin-ajax.php'); ?;
/script
script
$(#enquiry_email_form).on(submit, function (event) {
event.preventDefault();
var form= $(this);
var ajaxurl = form.data(url);
var detail_info = {
post_title: form.find(#post_title).val(),
post_description: form.find(#post_description).val()
}
if(detail_info.post_title === || detail_info.post_description === ) {
alert(Fields cannot be blank);
return;
}
$.ajax({
url: ajaxurl,
type: 'POST',
data: {
post_details : detail_info,
action: 'save_post_details_form' // this is going to be used inside wordpress functions.php
},
error: function(error) {
alert(Insert Failed + error);
},
success: function(response) {
modal.style.display = block;
body.style.position = static;
body.style.height = 100%;
body.style.overflow = hidden;
}
});
})
/script
button id=btnModalAbrir modal/button
div id=tvesModal class=modalContainer
div class=modal-content
span class=close×/span
h2Modal/h2
p?php ***echo $title_post, $url, $ID*** ?/p
/div
/div
function.php
function save_enquiry_form_action() {
$post_title = $_POST['post_details']['post_title'];
$post_description = $_POST['post_details']['post_description'];
$args = [
'post_title'= $post_title,
'post_content'=$post_description,
'post_status'= 'publish',
'post_type'= 'post',
'show_in_rest' = true,
'post_date'= get_the_date()
];
$is_post_inserted = wp_insert_post($args);
if($is_post_inserted) {
return success;
} else {
return failed;
}
}
Topic media-modal ajax jquery Wordpress
Category Web