Custom Meta Box Data Disappearing
-
I am using a custom meta box to hold the URL of an .mp3. Then placing that URL within the template in a specific place to become an audio player. If no URL is added to the meta box, no player shows up. That all works fine 99.9% of the time. Evey once in a while the mp3 URL that’s saved into the database will disappear. Could be days after the post is published that it randomly disappears. I looked into the AUTOSAVE issue, but I have that written into my functions already. Not sure where to start now…
ANY help is much appreciated!!
Here is the full block of code functions:<?php // Hook into WordPress add_action( 'admin_init', 'add_custom_metabox' ); add_action( 'save_post', 'save_custom_url' ); // Add meta box function add_custom_metabox() { add_meta_box( 'custom-metabox', __( 'Audio URL' ), 'url_custom_metabox', 'post', 'normal', 'high' ); } // Display the metabox function url_custom_metabox() { global $post; //variable for AUDIO LINK $urlmp3 = get_post_meta($post->ID, "urlmp3", true); //variable for NPR AUDIO LINK $npr_urlmp3 = get_post_meta($post->ID, "npr_audio", true); ?> <p><label for="sitemp3">Paste link to audio file: (must begin with https://)<br /> <input style="width:98%;" placeholder="https://" id="sitemp3" size="37" name="sitemp3" value="<?php if( $urlmp3 ) echo $urlmp3; elseif( $npr_urlmp3 ) echo $npr_urlmp3; else echo '' ?>" /></label></p> <?php } //Process the custom metabox fields function save_custom_url( $post_id ) { global $post; <strong>//skip auto save if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; }</strong> //check for your post type only if( $post->post_type == "post" ){ if(isset( $_POST ) != "" ) { update_post_meta( $post->ID, 'urlmp3', $_POST['sitemp3'] ); }} } //Get and return the values for the URL and description function get_url_desc_box() { global $post; $urlmp3 = get_post_meta( $post->ID, 'urlmp3', true ); return $urlmp3; } ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom Meta Box Data Disappearing’ is closed to new replies.