Всем привет, есть #вопрос:
Помогите исправить код так что бы при нажатии кнопки "сохранить" в форме не создавалось 5 постов)))
1) Есть функция:
if ( isset( $_POST['post_id'] ) ) {
//update the existing post
$post_array['ID'] = $post_id;
wp_update_post( $post_array );
if ( isset( $_POST['phone'] ) ) {
update_user_meta( get_current_user_id(), 'ext_phone', $_POST['phone'] );
}
} else {
//save the new post
$post_array['post_author'] = get_current_user_id();
$post_id = wp_insert_post( $post_array );
if ( isset( $_POST['phone'] ) ) {
update_user_meta( get_current_user_id(), 'ext_phone', $_POST['phone'] );
}
}
Она выполняет действие либо дополнение либо публикация (сохранение) поста
2) Мне необходимо дополнить ее дополнительными графами для обновления или публикации (сохранения), я добавил их по примеру работающей функции, но теперь у меня публикуется 5 постов вместо 1 необходимого, я понимаю что это проиходит потому что функция написана мол: делай это 5 раз, а мне необходимо все это соеденить в 1 функцию, помогите пожалуйста исправить код....
// Добавляю соц сети
if ( isset( $_POST['post_id'] ) ) {
//update the existing post
$post_array['ID'] = $post_id;
wp_update_post( $post_array );
if ( isset( $_POST['vkontakte'] ) ) {
update_user_meta( get_current_user_id(), 'ext_vkontakte', $_POST['vkontakte'] );
}
} else {
//save the new post
$post_array['post_author'] = get_current_user_id();
$post_id = wp_insert_post( $post_array );
if ( isset( $_POST['vkontakte'] ) ) {
update_user_meta( get_current_user_id(), 'ext_vkontakte', $_POST['vkontakte'] );
}
}
if ( isset( $_POST['post_id'] ) ) {
//update the existing post
$post_array['ID'] = $post_id;
wp_update_post( $post_array );
if ( isset( $_POST['facebook'] ) ) {
update_user_meta( get_current_user_id(), 'ext_facebook', $_POST['facebook'] );
}
} else {
//save the new post
$post_array['post_author'] = get_current_user_id();
$post_id = wp_insert_post( $post_array );
if ( isset( $_POST['facebook'] ) ) {
update_user_meta( get_current_user_id(), 'ext_facebook', $_POST['facebook'] );
}
}
if ( isset( $_POST['post_id'] ) ) {
//update the existing post
$post_array['ID'] = $post_id;
wp_update_post( $post_array );
if ( isset( $_POST['instagram'] ) ) {
update_user_meta( get_current_user_id(), 'ext_instagram', $_POST['instagram'] );
}
} else {
//save the new post
$post_array['post_author'] = get_current_user_id();
$post_id = wp_insert_post( $post_array );
if ( isset( $_POST['instagram'] ) ) {
update_user_meta( get_current_user_id(), 'ext_instagram', $_POST['instagram'] );
}
}
if ( isset( $_POST['post_id'] ) ) {
//update the existing post
$post_array['ID'] = $post_id;
wp_update_post( $post_array );
if ( isset( $_POST['telegram'] ) ) {
update_user_meta( get_current_user_id(), 'ext_telegram', $_POST['telegram'] );
}
} else {
//save the new post
$post_array['post_author'] = get_current_user_id();
$post_id = wp_insert_post( $post_array );
if ( isset( $_POST['telegram'] ) ) {
update_user_meta( get_current_user_id(), 'ext_telegram', $_POST['telegram'] );
}
}