Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function add_image_attachment_fields_to_edit($form_fields, $post) {
- // $form_fields is a an array of fields to include in the attachment form
- // $post is nothing but attachment record in the database
- // $post->post_type == 'attachment'
- // attachments are considered as posts in WordPress. So value of post_type in wp_posts table will be attachment
- // now add our custom field to the $form_fields array
- // input type="text" name/id="attachments[$attachment->ID][custom1]"
- $categories = get_categories();
- //var_dump($categories);
- $form_fields["custom4"]["label"] = __("Custom Select");
- $form_fields["custom4"]["input"] = "html";
- $form_fields["custom4"]["html"] = "<select name='attachments[{$post->ID}][custom4]' id='attachments[{$post->ID}][custom4]'>";
- foreach ($categories as $category) {
- $form_fields["custom4"]["html"] .= '<option value="$category">' . $category . '</option>';
- }
- $form_fields["custom4"]["html"] .= "</select>";
- return $form_fields;
- }
- // now attach our function to the hook
- add_filter("attachment_fields_to_edit", "add_image_attachment_fields_to_edit", null, 2);
- function add_image_attachment_fields_to_save($post, $attachment) {
- // $attachment part of the form $_POST ($_POST[attachments][postID])
- // $post['post_type'] == 'attachment'
- if( isset($attachment['restaurant']) ){
- // update_post_meta(postID, meta_key, meta_value);
- update_post_meta($post['ID'], '_restauarant', $attachment['restaurant']);
- }
- return $post;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement