Добавление второго метабокса
-
Всем привет!
Подскажите, пожалуйста, как добавить второй метабокс? Один уже есть и при попытке добавления второго выдается такая ошибка: Fatal error: Cannot redeclare add_custom_date_box() (previously declared in /home/intastelv/public_html/wp-content/themes/trendyblog-theme/functions.php:114) in /home/intastelv/public_html/wp-content/themes/trendyblog-theme/functions.php on line 162Код первого метабокса:
**/ function add_custom_date_box() { $screens = array( 'post', 'page' ); foreach ( $screens as $screen ){ add_meta_box( 'custom_date_section', 'Дата мероприятия', 'custom_date_box_callback', $screen ); } } add_action('add_meta_boxes', 'add_custom_date_box'); function custom_date_box_callback($post, $metabox) { wp_nonce_field( plugin_basename(__FILE__), 'custom_date_noncename' ); $value = get_post_meta( $post->ID, '_custom_date_value_key', true ); wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_style("jquery-ui-datepicker", 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/themes/smoothness/jquery-ui.css'); echo '<label for="custom_date_field">' . __("", 'Дата' ) . '</label> '; echo '<input type="text" id= "custom_date_field" name="custom_date_field" placeholder = "дд.мм.гггг H:M" size="13" />'; } function custom_date_save( $post_id ) { if ( ! wp_verify_nonce( $_POST['custom_date_noncename'], plugin_basename(__FILE__) ) ) return $post_id; if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; if ( 'page' == $_POST['post_type'] && ! current_user_can( 'edit_page', $post_id ) ) { return $post_id; } elseif( ! current_user_can( 'edit_post', $post_id ) ) { return $post_id; } if ( ! isset( $_POST['custom_date_field'] ) ) return; $my_data = sanitize_text_field( $_POST['custom_date_field'] ); update_post_meta( $post_id, '_custom_date_value_key', $my_data ); } add_action( 'save_post', 'custom_date_save' ); /**
Где изменить идентификаторы, чтобы не было сбоев?
Просмотр 2 ответов — с 1 по 2 (всего 2)
Просмотр 2 ответов — с 1 по 2 (всего 2)
- Тема «Добавление второго метабокса» закрыта для новых ответов.