function wpt_save_testimonials_meta( $post_id, $post ) {
// Return if the user doesn't have edit permissions.
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
// Verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times.
if ( ! isset( $_POST['name'] ) ||! isset( $_POST['designation'] ) ||! isset( $_POST['company'] ) ||! isset( $_POST['description'] ) || ! wp_verify_nonce( $_POST['testimonial_fields'], basename(__FILE__) ) ) {
return $post_id;
}
// Now that we're authenticated, time to save the data.
// This sanitizes the data from the field and saves it into an array $events_meta.
$events_meta['description'] = esc_textarea( $_POST['description'] );
$events_meta['name'] = esc_textarea( $_POST['name'] );
$events_meta['designation'] = esc_textarea( $_POST['designation'] );
$events_meta['company'] = esc_textarea( $_POST['company'] );
// Cycle through the $events_meta array.
// Note, in this example we just have one item, but this is helpful if you have multiple.
foreach ( $events_meta as $key => $value ) :
// Don't store custom data twice
if ( 'revision' === $post->post_type ) {
return;
}
if ( get_post_meta( $post_id, $key, false ) ) {
// If the custom field already has a value, update it.
//update_post_meta( $post_id, $key, $value );
global $wpdb;
$wpdb->update($wpdb->prefix.'my_testimonial', array(
'post_id' => $post_id,
'name' => $name,
'description' => $description,
'designation' => $designation,
'company' => $company
));
} else {
// If the custom field doesn't have a value, add it.
add_post_meta( $post_id, $key, $value);
}
if ( ! $value ) {
// Delete the meta key if there's no value
delete_post_meta( $post_id, $key );
}
endforeach;
}
add_action( 'save_post', 'wpt_save_testimonials_meta', 10, 2 );
Я пытаюсь создать плагин, используя мета-блоки. таблица создается при активации, но обновление вызывает следующую ошибку. Я перепробовал много ответов в стеке, но не смог найти правильный ответ. Пожалуйста, кто-нибудь Помогите мне с этой проблемой, упомянутой ниже.
Fatal error: Uncaught ArgumentCountError: Too few arguments to function wpdb::update()