is it possible to add extra fields via the functions.php script for attachments in wordpress?
Tried loads of examples but none seem to work. Worried an existing plugin might be affecting my attempts but its not clear if its even possible.
best, dan.
Here is a tutorial that shows how to add custom fields to the attachments/media gallery/thickbox/iframe/whatever-you-call it overlay.
I’ve successfully used it, but have not yet taken it much further by adding radio buttons/checkboxes/etc or messed with limiting the changes to particular post types, but that all looks completely doable too.
Here is the code from the link above, just in case it disappears some day:
1) ‘attachment_fields_to_edit’ : We will attach a function to this hook which will do the job of adding a custom field to Media Gallery.
2) ‘attachment_fields_to_save’ : This in turn will accept and save the user input.
Here is a very good tutorial (with source files), explains how to add custom fields for images, attachments, textareas…and everything else you may need for your posts.
http://www.deluxeblogtips.com/2010/05/howto-meta-box-wordpress.html
You need to use the
update_post_meta()
(Codex) function:<?php update_post_meta($post_id, $meta_key, $meta_value, $prev_value); ?>
What are you trying to do, that isn’t working?
You will find good sample code in the answers to question: How can I add a URL field to the attachments window?