WordPress.org

Ready to get started?Download WordPress

Forums

Autosave empties Custom Post Fields (5 posts)

  1. mahype
    Member
    Posted 4 years ago #

    Hello!

    Im saving title, description an Keywords by a selfmade form area in the bottom of the posts. The fields where saved in the postmeta fields:

    _title
    _keywords
    _description

    I'm running the save_post adhook to save my post data:

    add_action('save_post','post_seo4all_keywords');

    So far it's working. But if I leave open the post, the autosave function runs and after some minutes all my data (_title,_description and _keywords) in the postmeta tables is empty.

    Has anybody an idea, whats happened to my data?

    Thanks!

  2. prettyboymp
    Member
    Posted 4 years ago #

    The save_post action runs on autosave as well, but autosave doesn't post back custom fields. You need to check against wp_is_autosave($post_id) and wp_is_post_revision($post_id) before updating the meta values.

  3. azureardee
    Member
    Posted 3 years ago #

    Strange, the function wp_is_autosave()doesn't seem to exist

  4. azureardee
    Member
    Posted 3 years ago #

    I guess what you need is DOING_AUTOSAVE: (from http://www.andrewgail.com/wordpress-autosave-and-custom-fields/)

    global $post;
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
    return $post->ID;
    }

  5. gekido
    Member
    Posted 3 years ago #

    gotta love how the dev's claim that the autosave functionality is a 'stop gap designed to prevent losing data', when this behavior is doing exactly that - losing data.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags