A
A
Alexander Sobolev2018-06-27 12:16:51
WordPress
Alexander Sobolev, 2018-06-27 12:16:51

update_post_meta doesn't work. What am I doing wrong?

In the code below, update_post_meta does not work.

function edit_servise( /*$servise_id,	$current_servise_key, $current_servise_label, $current_servise_cost, $upd_servise_label, $upd_servise_cost*/ ){
 global $wpdb;
 if( isset($_POST['servise_id']) and isset($_POST['current_servise_key']) and isset($_POST['current_servise_label']) and isset($_POST['current_servise_cost']) and isset($_POST['upd_servise_label']) and isset($_POST['upd_servise_cost']) ){
 	
 	$servise_id = $_POST['servise_id'];
 	$current_servise_key = $_POST['current_servise_key'];
 	$current_servise_label = $_POST['current_servise_label'];
 	$current_servise_cost = $_POST['current_servise_cost'];
 	$upd_servise_label = $_POST['upd_servise_label'];
 	$upd_servise_cost = $_POST['upd_servise_cost'];
 	
 	$upd_label = update_post_meta( $servise_id, "_".$current_servise_key, $upd_servise_label, $current_servise_label );
 	if ($upd_label){ $label_msg = 'Название изменено успешно !';} else {$label_msg="Название изменено не было..";}
 	
 	$upd_cost = update_post_meta( $servise_id, $current_servise_key, $upd_servise_cost, $current_servise_cost );
 	if($upd_cost){	$cost_msg = 'Стоимость услуги обновлена !';} else {$cost_msg=" Стоимость осталась прежней..";}

 	echo 'Ответ сервера: '.$label_msg.', новое название '.$upd_servise_label.' текущее название '.$current_servise_label.' | ключ '.$current_servise_key.' сообщение стоимости '.$cost_msg;

 }
 else {echo 'Упс.. Что-то пошло не так..';}
}

The data is coming in correctly. Ajax fulfills its purpose. In the console report, he writes everything that came, and that the name was not changed and the cost remained the same. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
niceandriyanov, 2020-09-17
@niceandriyanov

Just call delete_post_meta( $post_id, $key, $value ); and you will be happy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question