Note that there are some explanatory texts on larger screens.

plurals
  1. POWordpress plugin data disappearing
    primarykey
    data
    text
    <p>I'm working on a simple plug that lets me save pairs of values with a post; there's a bit of JS to add or delete pairings. Everything works just fine, but randomly data will disappear. I'm not sure if it's a problem with autosaving or what, but I'd thought I'd accounted for that.</p> <p>Any ideas why my data is saving, but disappearing randomly?</p> <pre><code>&lt;?php function esys_menus() { if (function_exists('add_meta_box')) { add_meta_box('esys_box','Energy System Details','esys_meta','energy-systems'); } } function esys_meta() { global $wpdb, $post_ID; $files = esys_get_files($post_ID); ?&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th width="50%"&gt;BPM&lt;/th&gt; &lt;th width="50%"&gt;Duration&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php $i = 0; if ($files &amp;&amp; $post_ID) { foreach ((array)$files as $file) { ?&gt; &lt;tr id="esys-&lt;?php echo $i; ?&gt;"&gt; &lt;td&gt;&lt;input type="text" name="esys[&lt;?php echo $i; ?&gt;][bpm]" value="&lt;?php echo $file['bpm']; ?&gt;" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="esys[&lt;?php echo $i; ?&gt;][duration]" value="&lt;?php echo $file['duration']; ?&gt;" /&gt;&lt;/td&gt; &lt;td&gt;&lt;a href="#" class="button" onclick="esys_remove(&lt;?php echo $i; ?&gt;); return false;"&gt;X&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php $i++; }; }; ?&gt; &lt;tr id="esys-&lt;?php echo $i; ?&gt;"&gt; &lt;td&gt;&lt;input type="text" name="esys[&lt;?php echo $i; ?&gt;][bpm]" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="esys[&lt;?php echo $i; ?&gt;][duration]" /&gt;&lt;/td&gt; &lt;td&gt;&lt;a href="#" class="button" onclick="esys_remove(&lt;?php echo $i; ?&gt;); return false;"&gt;X&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p align="right" style="padding:10px 0 5px; margin:0;"&gt;&lt;a href="#" class="button" id="add-esys-file"&gt;Add&lt;/a&gt;&lt;/p&gt; &lt;?php } function esys_get_files($ID) { $data = unserialize(get_option("esys-files")); return ($ID) ? $data[$ID] : $data; } function esys_delete() { delete_option('esys-files'); } function esys_submit($post_ID) { global $wpdb; if ( defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE ) { return $post_id; } $data = esys_get_files($post_ID); foreach((array)$_POST['esys'] as $file) { $t[] = $file; $data[$post_ID] = $t; } esys_update_files($data); } function esys_update_files($data) { update_option('esys-files', serialize($data)); } function esys_admin_head() { echo '&lt;link type="text/css" rel="stylesheet" media="all" href="'.plugins_url('energy-systems-module/admin.css').'" /&gt;'."\n"; echo '&lt;script type="text/javascript" src="'.plugins_url('energy-systems-module/esys.js').'"&gt;&lt;/script&gt;'."\n"; } add_action('admin_head', 'esys_admin_head'); add_action('admin_menu', 'esys_menus'); add_action('save_post', 'esys_submit'); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload