2015-12-23 53 views
0

問題:是否可以像使用update_post_meta()一樣使用函數來更新WordPress帖子的元框值?使用某些WordPress功能更新Meta Box值。可能?

說明: 這裏是因爲我想用一個函數/鉤來更新metabox保存在數據庫中的數據的格式。 enter image description here

現在,如果我想更新只從數據單一入口,讓說「START_YEAR」話,我怎麼能做到這一點使用函數/掛鉤?

如果我選擇使用update_post_meta(65,'_mycpt_date','2010),它顯然會取代所有內容,只是'2010'。

回答

0

在做了一些頭腦風暴和this的幫助之後,我用一點辦法解決了這個問題。

// Storing the value/array in the variable. 
    $options = get_post_meta(65, '_chronos_date', true); 

// Updating the new value using key-value pair. That way, other parts of the array would remain un-touched. 
    $options['start_year']= "2000"; 

// Update the new value. 
update_post_meta(65,'_chronos_date',$options); 

很快。我希望它能幫助別人。