Add custom drop down media metadata field
-
Sorry for the crosspost, just realised that I should be posting here.
I have my code as a standalone plugin to keep it clean. So far, I’ve been able to get custom check box and text fields working, that is to save states and retrieve them from the saved attachment metadata, but I am completely stuck with saving and retrieving a value (even just echoing it) via drop down menu. I’ve searched exhaustively, but everything seems to reference checkboxes or other alternativesh.
The point of all this is to allow gallery exclusion of panorama images, while displaying the panorama images separately. I want to add a drop down field to the media metadata so I can select the type of panorama image that is saved in each specific attachment, using default gallery not some other one like NextGen. It seems simple enough, but I’m stuck. This code works insofar as to display a drop down menu when editing an attachment, but for whatever reason, I can’t get the selected value from the drop down to save in the metadata for future retrieval.
/** * Add custom media metadata fields */ function add_image_attachment_fields_to_edit( $form_fields, $post ) { $panorama_types = "<select name='attachments[{$post->ID}][panorama]' id='attachments[{$post->ID}][panorama]'> <option value=''> </option> <option value='nature'>Nature</option> <option value='city'>City</option> <option value='other'>Other</option> </select>"; // Add Panorama field $form_fields['panorama'] = array( 'label' => __('Panorama'), 'input' => 'html', 'html' => $panorama_types, 'helps' => __("Select type of panorama if applicable.") ); return $form_fields; } add_filter("attachment_fields_to_edit", "add_image_attachment_fields_to_edit", null, 2); /** * Save custom media metadata fields */ function add_image_attachment_fields_to_save( $post, $attachment ) { if ( isset( $attachment['panorama'] ) ) update_post_meta( $post['ID'], '_panorama', $attachment['panorama'] ); return $post; } add_filter("attachment_fields_to_save", "add_image_attachment_fields_to_save", null , 2);
- The topic ‘Add custom drop down media metadata field’ is closed to new replies.