Leave a Reply

2 comments

  1. You aren’t retrieving the saved data and populating the form.

    function swpd_render_info_fields()
    {
        ?>
        <label for="swpd_comany_addr">Company Address</label>
        <input type="text" name="swpd_company_addr" id="swpd_company_addr" />
        <?php
    }
    

    There is nothing in that function that would insert your saved data. You just write a blank form every time. You need to be conditionally populating the input value.

    function swpd_render_info_fields($post)
    {
        $meta = get_post_meta($post->ID);
        $value = (!empty($meta['swpd_company_addr'])) 
            ? $meta['swpd_company_addr']
            : '';
        ?>
        <label for="swpd_comany_addr">Company Address</label>
        <input type="text" name="swpd_company_addr" id="swpd_company_addr" value="<?php echo $value ?>" />
        <?php
    }
    

    I am guessing a lot at how your code works but that is the idea. You have to populate the form with existing values from the DB or you are just starting over each time.

  2. Your custom data is deleted during autosave, because you forgot to check that. Extend your save handler:

    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
        return;
    

    The autosave will trigger save_post, but custom fields are not sent.