2013-10-03 28 views
1

如何更新自定義發佈自定義字段的值當郵政保存在管理員?更新後自定義發佈自定義字段值當郵政保存在wp-admin

我試圖在misc.php使用此爲管理部分:

add_action('pre_post_update', 'do_something_with_a_post'); 
function do_something_with_a_post($id) { 

    global $post; 
    update_post_meta($id, 'ct_Course_Dur_text_d19c', 'test12'); 

) 

但它無法正常工作。

+0

你的意思是你的自定義字段值arnt節省後保存? – codepixlabs

回答

3

你可以試試這個(使用save_post鉤),在functions.php文件

function save_cpt_metadata($id, $post) 
{ 
    if($post->post_type != 'your_custom_post_type') { 
     return; 
    } 
    update_post_meta($id, 'ct_Course_Dur_text_d19c', sanitize_text_field($_POST['your_custom_field'])); 
} 
add_action('save_post', 'save_cpt_metadata'); 

粘貼此代碼在這個例子中sanitize_text_field($_POST['your_custom_field'])是實際上是表單上的cstom場,但你可以使用任何硬編碼數據,用您真正的自定義帖子類型替換your_custom_post_type

相關問題