Answer the question
In order to leave comments, you need to log in
Wp_isert_post for custom_post_type. How right?
if( isset($_POST['estate_data']) and !empty($_POST['estate_data']) ){
$estate_data = $_POST['estate_data'];
$estate_type = get_term_by('id', $estate_data['estate_type'],'estate_type');
$proprietor_id = get_current_user_id();
$estate_object_data = array(
'post_type' => 'estate',
'post_title' => 'Объект '.$estate_data['estate_address_street'].' '.$estate_type->name.' '.$estate_data['estate_rooms_count'].'-ка',
'post_content' => 'Объект '.$estate_data['estate_address_street'].' '.$estate_type->name.' '.$estate_data['estate_rooms_count'].'-ка',
'post_status' => 'publish',
'post_author' => $proprietor_id,
'post_category' => array(
$estate_data['estate_district'], $estate_data['estate_type'],
$estate_data['estate_building_type'], $estate_data['estate_operation'],
$estate_data['estate_class'], $estate_data['estate_proprietor']
),
);
$new_estate_id = wp_insert_post($post_data, true);
/*$taxonomies = array('estate_district', 'estate_type', 'estate_building_type', 'estate_operation', 'estate_class', 'estate_proprietor');
foreach ($estate_data as $key => $value){
if ( !in_array($key, $taxonomies) ){
add_post_meta( $new_estate_id, $key, $value, true );
}
} */
wp_send_json('Объект успешно добавлен, его ID = '.$new_estate_id); wp_die();
}
Answer the question
In order to leave comments, you need to log in
500 does not apply to wp_insert_post in any way!
You here and read: https://wp-kama.ru/id_2018/ajax-v-wordpress.html
It seems to me that you just need to load the VI environment before executing its f-th :)
require_once $_SERVER["DOCUMENT_ROOT"]."/wp-load.php";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question