Meta data is being deleted.
-
Hey guys…
I have a set of fields setup which get either drawn or not based on which taxonomy the object is associated with. Everything works great, however if the user switches the taxonomy and then switches back again to the same taxonomy all the meta values are deleted.
Here is an illustration:
Original Content
https://www.flowpress.com/screenshots/Screenshot_2017-04-11_10.43.16.png
https://www.flowpress.com/screenshots/Screenshot_2017-04-11_10.43.29.pngI’ll switch the catalog taxonomy and save
https://www.flowpress.com/screenshots/Screenshot_2017-04-11_10.44.10.png
Data is still in the db (which is what I want)
https://www.flowpress.com/screenshots/Screenshot_2017-04-11_10.44.23.pngThen I switch back to the original taxonomy and save
https://www.flowpress.com/screenshots/Screenshot_2017-04-11_10.44.53.png
https://www.flowpress.com/screenshots/Screenshot_2017-04-11_10.45.03.pngAll the original fields are zeroed out and deleted.
As you can see below I’m not doing anything too complex just drawing the fields based on which taxonomy is selected and would like the data to remain if the user switches between taxonomies.
function asd($a,$b){ global $product_fields; $field_name = $a->args['name']; $field_id = $a->args['id']; $catalog = wp_get_post_terms( $a->object_id, 'catalog' ); // var_dump($product_fields[$catalog[0]->name]); // var_dump($field_name); // var_dump($field_id); // var_dump($catalog[0]->name); // var_dump($product_fields[$catalog[0]->name]); // var_dump($product_fields[$catalog[0]->name][$field_name]); if (isset($product_fields[$catalog[0]->name][$field_name])) { return true; } if (isset($product_fields[$catalog[0]->name][$field_id])) { return true; } return false; } function product(){ global $wpdb, $product_fields, $post; $cmb = new_cmb2_box( array( 'id' => 'product_data', 'title' => __( 'Product Data', 'cmb2' ), 'object_types' => array( 'product', ), // Post type 'context' => 'normal', // 'show_on' => array( 'key' => 'id', 'value' => array( 2190 ) ), 'priority' => 'high', 'show_names' => true, // Show field names on the left // 'cmb_styles' => false, // false to disable the CMB stylesheet // 'closed' => true, // Keep the metabox closed by default ) ); $cmb->add_field( array( 'name' => __( 'Watt Density', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'watt_density', 'type' => 'text', 'attributes' => array( 'type' => 'number', 'pattern' => '\d*', ), 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Weight (kg)', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'weight-kg', 'type' => 'text', 'attributes' => array( 'type' => 'number', 'pattern' => '\d*', ), 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Screw Plug Size', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'screw-plug-size', 'type' => 'text', 'attributes' => array( 'type' => 'number', 'pattern' => '\d*', ), 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Item #', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'item-number', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Number Of Elements', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'number-of-elements', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Flange Type', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'flange-type', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Flange Size (In)', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'flange-size-in', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Immersed Length B (In)', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'immersed-length-b-in', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Immersed Length B (mm)', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'immersed-length-b-mm', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Power (kw)', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'power-kw', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Voltage', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'voltage', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Watt Density (W/cm²)', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'watt-density-wcmsup2', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Watt Density (W/incm²)', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'watt-density-winsup2', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Element Type', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'element-type', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Net Weight', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'net-weight', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Thermostat', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'thermostat', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); $cmb->add_field( array( 'name' => __( 'Terminal Enclosure', 'cmb2' ), 'desc' => __( '', 'cmb2' ), 'id' => 'terminal-enclosure', 'type' => 'text', 'show_on_cb' => 'Wattco\assets\php\asd' ) ); }
- The topic ‘Meta data is being deleted.’ is closed to new replies.