Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeatable/Sortable fields not saving sort order #39

Open
wesdekoninck opened this issue Mar 25, 2013 · 2 comments
Open

Repeatable/Sortable fields not saving sort order #39

wesdekoninck opened this issue Mar 25, 2013 · 2 comments

Comments

@wesdekoninck
Copy link

I am having trouble with the Repeatable/Sortable field type. The information is saved correctly and I can create/delete repeatable fields, but after resorting them, the new position is not being saved. Is there something that I am missing?

You will find the field setup that I am using for this field below.

Thank you in advance for the help!


$location_offer_fields = array(
        array( 
        'label' => '', 
        'desc'  => 'Enter your location offers above', 
        'id'    => $prefix.'location_offers', 
        'type'  => 'repeatable', 
        'sanitizer' => array( 
            'title' => 'sanitize_text_field',
            'desc' => 'wp_kses_data'
        ),
        'sanitizer' => array( 
            'title' => 'sanitize_text_field',
            'desc' => 'wp_kses_data'
        ),
        'repeatable_fields' => array( 
            'title' => array(
                'label' => 'Title',
                'id' => 'title',
                'type' => 'text'
            ),
            'desc' => array(
                'label' => 'Description',
                'id' => 'desc',
                'type' => 'textarea'
            )
        )
    )
    );
    

@ghost
Copy link

ghost commented Oct 1, 2013

Bump - I'm having the same issues here.
I looked at your code - perhaps it's the two sanitizer's? Any help on this would really be appreciated

@ghost
Copy link

ghost commented Oct 1, 2013

I think I got it - or at least this worked for me. At the bottom of the meta_box.php you had to add one line of code.

Hope this helps!

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
$new = false;
$old = get_post_meta( $post_id, $field['id'], true );
if ( isset( $_POST[$field['id']] ) )
$new = $_POST[$field['id']];
if($field['type'] == 'repeatable')
$new = array_values($new);
if ( isset( $new ) && '' == $new && $old ) {
delete_post_meta( $post_id, $field['id'], $old );
} elseif ( 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 );
if( $field['type'] == 'date') {
$new = strtotime($new);
}
update_post_meta( $post_id, $field['id'], $new );
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant