WordPress中的自动保存和自定义字段[关闭]

WordPress中的自动保存和自定义字段[关闭]

问题描述:

I was having the problem with WordPress autosave not sending custom field data, and found this entry on SO:

Wordpress add_meta_box() weirdness

The approved answer works, but is it not just preventing any autosave from happening by returning early? Isn't the same as disabling autosave completely? If so, wouldn't it be better to do so in the proper way instead of letting it try to autosave just to prevent it?

The only exception I could see is if one checked for a post-type before checking for autosave so that you only disabled autosave for certain post types.

I'm going to be disabling autosave completely, but was wondering what you guys thought.

EDIT: I'm not having problems with the autosave anymore. This question is to discuss the merits of the solutions that I mentioned above.

Additionally, I can't see how this would be a feature of WordPress, and would assume that autosave should be changed to include all post data. No?

我遇到了WordPress自动保存不发送自定义字段数据的问题,并在SO上找到了这个条目: p >

Wordpress add_meta_box()奇怪 p> \ n

批准的答案有效,但它不仅仅是通过提前返回来防止任何自动保存发生吗? 是否完全禁用自动保存? 如果是这样,以正确的方式这样做是不是更好,而不是让它试图自动保存以防止它? p>

我能看到的唯一例外是如果检查一个 在检查自动保存之前的一个post-type,这样你只能为某些帖子类型禁用自动保存。 p>

我将完全禁用自动保存,但是想知道你们的想法。 p>

编辑:我不再遇到自动保存问题了。 这个问题是讨论我上面提到的解决方案的优点。 p>

此外,我看不出这将是WordPress的一个功能,并假设应该更改自动保存 包括所有发布数据。 不是吗? p> div>

The code in the linked answer does not disable autosave, it only stops a custom save function executing when autosaving. This is necessary because the Wordpress autosave system does not support post meta data (custom fields), either in the Javascript which collates the post data or in the PHP which creates and restores revisions.

I've used the following for Custom Fields I've created and it's worked fine.

<?php
// Save Fields
add_action('save_post', 'save_details');

function save_details(){
 if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
    return $post_id;
 global $post;
 update_post_meta($post->ID, "event_featuring", $_POST["event_featuring"]);
 update_post_meta($post->ID, "event_time", $_POST["event_time"]);
 update_post_meta($post->ID, "event_date", $_POST["event_date"]);
 update_post_meta($post->ID, "event_end_date", $_POST["event_end_date"]);
 update_post_meta($post->ID, "event_location", $_POST["event_location"]);
 update_post_meta($post->ID, "bhs_event", $_POST["bhs_event"]);
}
?>

FYI, the solution posted here http://wordpress.org/support/topic/custom-post-type-information-disappearing worked for me and I think is much more elegant.