Answer the question
In order to leave comments, you need to log in
Why is metabox custom field data not updating?
Hello. I create a custom metabox, but for some reason the data from it is not updated in the database.
Here I create the metabox itself:
function cgc_tour_meta_box() {
add_meta_box(
'tour_meta_box',
'Tournament Meta Box',
'cgc_display_meta_box', //callback
'tour',
'normal',
'high'
);
}
add_action( 'add_meta_boxes', 'cgc_tour_meta_box' );
function cgc_display_meta_box( $post ) {
$title = get_post_meta( $post -> ID, 'tour_title', true );
?>
<!-- Название турнира -->
<div class="meta-row">
<div class="meta-th">
<label for="tour-title" class="cgc-row-title">Tournament Title</label>
</div>
<div class="meta-td">
<input type="text" id="tour-title" name="tour-title" value="<?php echo $title ?>">
</div>
</div>
<?php
}
function cgc_meta_save( $post_id ) {
if ( isset( $_POST['tour_title'] ) && $_POST['tour_title'] != '' ) {
update_post_meta( $post_id, 'tour_title', sanitize_text_field( $_POST[ 'tour_title' ] ) );
}
}
add_action( 'save_post', 'cgc_meta_save' );
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question