Save jquery to custom field
-
Is there a way to save jquery data into a custom field? What my metabox does is allow a user to send a file that gets analyzed and shows the size of the file and the total time duration. When I save the post, it doesn’t save the jquery data to a custom field.
function analyize_mp3_add_meta_box() { add_meta_box( 'analyize_mp3-analyize-mp3', __( 'Analyize MP3', 'analyize_mp3' ), 'analyize_mp3_html', 'post', 'normal', 'default' ); } add_action( 'add_meta_boxes', 'analyize_mp3_add_meta_box' ); function analyize_mp3_html( $post) { wp_nonce_field( '_analyize_mp3_nonce', 'analyize_mp3_nonce' ); ?> <script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script> <style type="text/css"> audio { display: none; } </style> <script type='text/javascript'>//<![CDATA[ $(function(){ var objectUrl; $("#audio").on("canplaythrough", function(e){ var seconds = e.currentTarget.duration; var duration = moment.duration(seconds, "seconds"); var time = ""; var hours = duration.hours(); if (hours > 0) { time = hours + ":" ; } time = time + duration.minutes() + ":" + duration.seconds(); $("#duration").text(time); var metavalue = $("#duration").text(time).val(); URL.revokeObjectURL(objectUrl); }); $("#file").change(function(e){ var file = e.currentTarget.files[0]; $("#filesize").text(file.size); objectUrl = URL.createObjectURL(file); $("#audio").prop("src", objectUrl); }); });//]]> </script> <p>Select a .mp3 file</p> <input type="file" id="file" /> <audio id="audio"></audio> <p> <label>File Size:</label> <span id="filesize"></span> </p> <p> <label>Song Duration:</label> <span id="duration"></span> </p> <?php } function analyize_mp3_save( $post_id ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if ( ! isset( $_POST['analyize_mp3_nonce'] ) || ! wp_verify_nonce( $_POST['analyize_mp3_nonce'], '_analyize_mp3_nonce' ) ) return; if ( ! current_user_can( 'edit_post', $post_id ) ) return; if ( isset( $_REQUEST['metavalue'] ) ) update_post_meta( $post_id, 'length', $_REQUEST['metavalue'] ); } add_action( 'save_post', 'analyize_mp3_save' );
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Save jquery to custom field’ is closed to new replies.