$old = get_post_meta($post_id, 'figure_sugsubject_repeatable_fields', true);
$new = array();
$figuresugsubjectpositions = $_POST['figuresugsubjectposition'];
$figuresugsubjectworkplaces = $_POST['figuresugsubjectworkplace'];
$figuresugsubjectlocations = $_POST['figuresugsubjectlocation'];
$figuresugsubjectfroms = $_POST['figuresugsubjectfrom'];
$figuresugsubjectstatuss = $_POST['figuresugsubjectstatus'];
$count = count( $figuresugsubjectpositions );
for ( $i = 0; $i < $count; $i++ ) {
if ( $figuresugsubjectpositions[$i] != '' ) :
$new[$i]['figuresugsubjectposition'] = stripslashes( strip_tags( $figuresugsubjectpositions[$i] ) );
$new[$i]['figuresugsubjectworkplace'] = $figuresugsubjectworkplaces[$i];
$new[$i]['figuresugsubjectlocation'] = $figuresugsubjectlocations[$i];
$new[$i]['figuresugsubjectfrom'] = $figuresugsubjectfroms[$i];
$new[$i]['figuresugsubjectstatus'] = $figuresugsubjectstatuss[$i];
endif;
}
if ( !empty( $new ) && $new != $old )
update_post_meta( $post_id, 'figure_sugsubject_repeatable_fields', $new );
elseif ( empty($new) && $old )
delete_post_meta( $post_id, 'figure_sugsubject_repeatable_fields', $old );
我有一个提交帖子的前端表格。我希望表单中的新条目不要替换旧条目,而是希望添加它。使用add_post_meta替换update_post_meta将无法解决问题,因为用户将无法编辑旧输入。
谢谢。