Custom checkbox field gets unchecked on drag n drop sort
-
On a custom post type, I created a custom checkbox field within the Featured Image metabox using admin_post_thumbnail_html, and saved it using save_post. However when I sort one of the items, that field gets unchecked automatically and therefore I have to open the post and recheck the checkbox and save it. (and it doesn’t always fall back into sorted place). Perhaps i need something else in my code which saves the state of that checkbox when i use your drag n drop sorting? I’d like to resolve this so my client can drag n drop without worrying about automatically getting that field unchecked. Thank you. I’ll display the code below:
// Add checkbox to Featured Image metabox for Featured Project add_filter( 'admin_post_thumbnail_html', 'add_featured_project_display_settings', 10, 2 ); function add_featured_project_display_settings( $content, $post_id ) { $field_id = 'featured_project'; $field_value = esc_attr( get_post_meta( $post_id, $field_id, true ) ); $field_text = esc_html__( 'Featured Project?', 'bloomer' ); $field_state = checked( $field_value, 1, false); $field_label = sprintf( '<p><label for="%1$s"><input type="checkbox" name="%1$s" id="%1$s" value="%2$s" %3$s> %4$s</label></p>', $field_id, $field_value, $field_state, $field_text ); return $content .= $field_label; } // // Save it add_action( 'save_post', 'save_featured_project_display_settings', 10, 3 ); function save_featured_project_display_settings( $post_id, $post, $update ) { $field_id = 'featured_project'; $field_value = isset( $_REQUEST[ $field_id ] ) ? 1 : 0; update_post_meta( $post_id, $field_id, $field_value ); } //
- The topic ‘Custom checkbox field gets unchecked on drag n drop sort’ is closed to new replies.