WordPress.org

Forums

Custom meta data disappears when I schedule a post. HELP!? (1 post)

  1. dakotatimmons
    Member
    Posted 2 years ago #

    Hellow all, I created a custom meta type that allows for me to add custom links with names and logos. Everything works from adding the links to putting it in draft status and publishing. However if I try to schedule it to go live at a later time, the meta data disappears. Anyone that can offer any help at all is appreciated!

    Here is my code:

    <?php
    // links-TYPE.php
    
    function Print_link_fileds($cnt, $p = null) {
    if ($p === null){
        $a = $b = $c = '';
    }else{
        $a = $p['n'];
        $b = $p['d'];
        $c = $p['p'];
    }
    $output_of_form .= '<li><label> Title: </label><input type="text" name="link_data[' . $cnt . '][n]" size="10" value="' . $a . '"/>';
    $output_of_form .= '<label> URL: </label><input type="text" name="link_data[' . $cnt . '][d]" size="70" value="' . $b . '"/>';
    $output_of_form .= '<label> Logo URL: </label><input type="text" name="link_data[' . $cnt . '][p]" id="upload_image' . $cnt . '" size="20" value="' . $c . '"/><input name="link_data[' . $cnt . '][p]" id="upload_image_button' . $cnt . '" value="Browse" type="button"><span class="remove"> Remove</span></li>';
    $output_of_form .= '<script>jQuery(document).ready(function() { jQuery(\'#upload_image_button' . $cnt . '\').click(function() {window.send_to_editor = function(html) {imgurl = jQuery(\'img\',html).attr(\'src\');jQuery(\'#upload_image' . $cnt . '\').val(imgurl); tb_remove();}; tb_show(\'\', \'media-upload.php?type=image&TB_iframe=true\');return false;});});</script>';
    return $output_of_form;
    }
    
    //add custom field - link
    add_action("add_meta_boxes", "object_init");
    
    function object_init(){
      add_meta_box("link_meta_id", "Featured Links:","link_meta", "post", "normal", "low");
    
    }
    
    function link_meta(){
     global $post;
    
      $data = get_post_meta($post->ID,"link_data",true);
      echo '<div>';
      echo '<ul id="link_items">';
      $c = 0;
        if (count($data) > 0){
            foreach((array)$data as $p ){
                if (isset($p['p']) || isset($p['d'])|| isset($p['n'])){
                    echo Print_link_fileds($c,$p);
                    $c = $c +1;
                }
            }
    
        }
        echo '</ul>';
    
        ?>
            <span id="here"></span>
            <span class="add"><?php echo __('Add Link'); ?></span>
            <script>
                var $ =jQuery.noConflict();
                    $(document).ready(function() {
                    var count = <?php echo $c; ?>;
                    $(".add").click(function() {
                        count = count + 1;
                        $('#link_items').append('<li><label>Title: </label><input type="text" name="link_data[' + count + '][n]" size="10" value=""/><label style="margin-left:10px;">URL: </label><input type="text" name="link_data[' + count + '][d]" size="70" value=""/><span class="remove" style="margin-left:10px;">Remove</span></li>');
                        return false;
                    });
                    $(".remove").live('click', function() {
                        $(this).parent().remove();
                    });
                });
            </script>
            <style>#link_items {list-style: none;}</style>
        <?php
        echo '</div>';
    }
    
    /**************************************************************************
     * Save the meta fields on save of the post
     **************************************************************************/
    function save_embed_tweet_meta($post_id) {
        // verify nonce
        if (!wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__)))
            return $post_id;
        // check autosave
        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
            return $post_id;
        // check permissions
        if ('page' == $_POST['post_type']) {
            if (!current_user_can('edit_page', $post_id))
                return $post_id;
            } elseif (!current_user_can('edit_post', $post_id)) {
                return $post_id;
        }
        $old = get_post_meta($post_id, "links_data", true);
        $new = $_POST["links_data"];
        if ($new && $new != $old) {
            update_post_meta($post_id, "links_data", $new);
        } elseif ('' == $new && $old) {
            delete_post_meta($post_id, "links_data", $old);
        }
    }
    add_action('save_post', 'save_embed_tweet_meta');
    
    function my_admin_scripts() {
    wp_enqueue_script('media-upload');
    wp_enqueue_script('thickbox');
    //wp_register_script('my-upload', get_bloginfo('template_url') . '/bf.js', array('jquery','media-upload','thickbox'));
    wp_enqueue_script('my-upload');
    }
    function my_admin_styles() {
    wp_enqueue_style('thickbox');
    }
    add_action('admin_print_scripts', 'my_admin_scripts');
    add_action('admin_print_styles', 'my_admin_styles');
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic