Meta Field not saving/updating
-
Funny Situation
Meta Box and Fields are rendered fine, but no data is saved
If I create a the field array “hardcoded” (with same id’s etc…) everything works just great…Code:
$forties_meta = new Super_Custom_Post_Meta( 'page' ); $forties_meta->add_meta_box( array( 'id' => 'page-forties', 'title' => '1940s', 'fields' => auto_add_historybox('1940') ) ); function auto_add_historybox($year) { /* $boxes_array = array( 'strauss_1950_image_1' => array( 'type' => 'file', 'label' => '1 - Image' ), 'strauss_1950_text_1' => array( 'label' => '1 - Paragraph', 'type' => 'textarea') ); */ $boxes_array = array(); //Add background image option $new_bg = 'strauss_'.$year.'_bg'; $boxes_array[$new_bg] = array( 'type' => 'file', 'label' => 'Background image for '.$year.'s' ); $counter = 1; if (isset($_GET['post'])) { $postid = $_GET['post']; if (get_post_meta($postid, 'strauss_'.$year, true) != '1') return; $continue = true; $stopInLoop = false; while($continue) { $new_img_fieldname = 'strauss_'.$year.'_image_'.$counter; $new_year_fieldname = 'strauss_'.$year.'_year_'.$counter; $new_title_fieldname = 'strauss_'.$year.'_title_'.$counter; $new_text_fieldname = 'strauss_'.$year.'_text_'.$counter; $boxes_array[$new_img_fieldname] = array( 'type' => 'file', 'label' => $counter . ' - Image' ); $boxes_array[$new_year_fieldname] = array( 'label' => $counter . ' - Year', 'type' => 'text'); $boxes_array[$new_title_fieldname] = array( 'label' => $counter . ' - Title', 'type' => 'text'); $boxes_array[$new_text_fieldname] = array( 'type' => 'textarea', 'label' => $counter . ' - Paragraph' ); if ($stopInLoop) break; if ( metadata_exists( 'post', $postid, $new_img_fieldname ) || metadata_exists( 'post', $postid, $new_year_fieldname ) || metadata_exists( 'post', $postid, $new_title_fieldname ) || metadata_exists( 'post', $postid, $new_text_fieldname ) ) { // Check If anything exists if (!( (strlen(get_post_meta($postid, $new_img_fieldname, true)) > 0) || (strlen(get_post_meta($postid, $new_year_fieldname, true)) > 0) || (strlen(get_post_meta($postid, $new_title_fieldname, true)) > 0) || (strlen(get_post_meta($postid, $new_text_fieldname, true)) > 0) )) { $stopInLoop = true; } } else { $continue = false; } $counter++; } return $boxes_array; } else { if ( empty($_POST) ) { $new_img_fieldname = 'strauss_'.$year.'_image_'.$counter; $new_year_fieldname = 'strauss_'.$year.'_year_'.$counter; $new_title_fieldname = 'strauss_'.$year.'_title_'.$counter; $new_text_fieldname = 'strauss_'.$year.'_text_'.$counter; $boxes_array[$new_img_fieldname] = array( 'type' => 'file', 'label' => $counter . ' - Image' ); $boxes_array[$new_year_fieldname] = array( 'label' => $counter . ' - Year', 'type' => 'text'); $boxes_array[$new_title_fieldname] = array( 'label' => $counter . ' - Title', 'type' => 'text'); $boxes_array[$new_text_fieldname] = array( 'type' => 'textarea', 'label' => $counter . ' - Paragraph' ); return $boxes_array; } } }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Meta Field not saving/updating’ is closed to new replies.