我遇到了一个让我困惑的问题:升级到WP 3.6后,当您重新订购时,我的可排序metabox字段没有保存它们的位置。下面是我的代码:
PHP:
function save_box( $post_id ) {
$post_type = get_post_type();
// verify nonce
if ( ! isset( $_POST[\'custom_meta_box_nonce_field\'] ) )
return $post_id;
if ( ! ( in_array( $post_type, $this->page ) || wp_verify_nonce( $_POST[\'custom_meta_box_nonce_field\'], \'custom_meta_box_nonce_action\' ) ) )
return $post_id;
// check autosave
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return $post_id;
// check permissions
if ( ! current_user_can( \'edit_page\', $post_id ) )
return $post_id;
// loop through fields and save the data
foreach ( $this->fields as $field ) {
if( $field[\'type\'] == \'section\' ) {
$sanitizer = null;
continue;
}
if( in_array( $field[\'type\'], array( \'tax_select\', \'tax_checkboxes\' ) ) ) {
// save taxonomies
if ( isset( $_POST[$field[\'id\']] ) ) {
$term = $_POST[$field[\'id\']];
wp_set_object_terms( $post_id, $term, $field[\'id\'] );
}
}
else {
// save the rest
$old = get_post_meta( $post_id, $field[\'id\'], $field[\'type\'], true );
if ( isset( $_POST[$field[\'id\']] ) )
$new = $_POST[$field[\'id\']];
if ( isset( $new ) && $new != $old ) {
$sanitizer = isset( $field[\'sanitizer\'] ) ? $field[\'sanitizer\'] : \'sanitize_text_field\';
if ( is_array( $new ) )
$new = meta_box_array_map_r( \'meta_box_sanitize\', $new, $sanitizer );
else
$new = meta_box_sanitize( $new, $sanitizer );
update_post_meta( $post_id, $field[\'id\'], $new );
} elseif ( isset( $new ) && \'\' == $new && $old ) {
delete_post_meta( $post_id, $field[\'id\'], $old );
}
}
} // end foreach
}
jQuery:
$(\'.meta_box_repeatable tbody\').sortable({
opacity: 0.6,
revert: true,
cursor: \'move\',
handle: \'.hndle\'
});
// post_drop_sort
$(\'.sort_list\').sortable({
connectWith: \'.sort_list\',
opacity: 0.6,
revert: true,
cursor: \'move\',
cancel: \'.post_drop_sort_area_name\',
items: \'li:not(.post_drop_sort_area_name)\',
update: function(event, ui) {
var result = $(this).sortable(\'toArray\');
var thisID = $(this).attr(\'id\');
$(\'.store-\' + thisID).val(result)
}
});
$(\'.sort_list\').disableSelection();
我有一个包含可重复框的元框,在可重复框内有一个图像上载按钮和标题文本输入。一切正常,我可以添加更多的可重复项并对其进行排序,但当我保存帖子时,可重复项会返回到其原始位置。
如果有人愿意,我可以提供您的登录详细信息,以查看实时版本。
任何帮助都将不胜感激。