Doesnt save custom field selectbox data in media-frame
-
As I descriped earlier here:
http://wordpress.org/support/topic/doesnt-save-custom-field-data-in-media-frameThe issue was fixed but a new problem appeared:
If I do not touch the values in my custom fields it does not save the value of the first option of the selectbox.
The code for my selectbox is here:
/** * Form fields */ function custom_attachment_fields_to_edit( $form_fields, $post ) { $form_fields['size'] = custom_attachment_fields_to_edit_cb( $post ); return $form_fields; } add_action( 'attachment_fields_to_edit', 'custom_attachment_fields_to_edit', 10, 2 ); /** * Form field callback */ function custom_attachment_fields_to_edit_cb( $post ) { $out_array = array( 'one-col' => __( 'One column' ), 'two-cols' => __( 'Two columns' ), 'full-row' => __( 'Full row') ); $out = '<select id="attachments-' . $post->ID . '-size" name="attachments[' . $post->ID . '][size]">'; foreach ( $out_array as $k => $v ) { $selected = selected( $k, get_post_meta( $post->ID, 'attachment_size', true ), false ); $out .= '<option value="' . $k . '"' . $selected .'>' . $v . '</option>'; } $out .= '</select>'; return array( 'label' => __( 'Size' ), 'input' => 'html', 'html' => $out, ); } /** * Save our gallery meta */ function custom_attachment_fields_to_save( $post, $attachment ) { if( isset( $attachment['size'] ) ) update_post_meta( $post['ID'], 'attachment_size', $attachment['size'] ); return $post; } add_filter( 'attachment_fields_to_save', 'custom_attachment_fields_to_save', 10, 2 );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Doesnt save custom field selectbox data in media-frame’ is closed to new replies.