• Hi,

    I have added some text input fields to metabox in my custom post. Now whenever I put some data in those text fields in admin panel and click ‘save’, all data vanishes. Here is the code:

    <?php
    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
    }
    /* * Process the custom metabox fields */
    add_action( 'save_post', 'swpd_save_info_fields',99 );
    function swpd_save_info_fields($post_id) {
        global $post;
        if(isset($_POST['post_type']) && ($_POST['post_type'] == "swpd_directory")){
            update_post_meta( $post->ID, 'swpd_company_addr', $_POST['swpd_company_addr'] );
        }
    }
    ?>

    I have checked the data passed to update_post_meta() and it seems o be fine, $post->ID containes the post ID and $_POST[‘swpd_company_addr’] containes the string I want to save to meta. What can be wrong?

Viewing 1 replies (of 1 total)
  • Hi hogo,

    I have the same problem, in my case i am passing an array as meta value but only the first element is saved. I also checked the values before calling the update_post_meta.

    I guess there is a problem within this function ‘update_post_meta’

Viewing 1 replies (of 1 total)
  • The topic ‘update_post_meta() not working in save_post’ is closed to new replies.