Skip to content

Instantly share code, notes, and snippets.

@ivandoric
Created April 23, 2014 15:14
Show Gist options
  • Save ivandoric/11219384 to your computer and use it in GitHub Desktop.
Save ivandoric/11219384 to your computer and use it in GitHub Desktop.
wordpress: Add custom field to gallery popup Wordpress
<?php
/* For adding custom field to gallery popup */
function ime_autora_field($form_fields, $post) {
$form_fields["ime-autora"] = array(
"label" => __("Autor"),
"input" => "text",
"value" => get_post_meta($post->ID, "_ime-autora", true),
"helps" => __("Ime autora slike"),
);
return $form_fields;
}
// now attach our function to the hook
add_filter("attachment_fields_to_edit", "ime_autora_field", null, 2);
function ime_autora_field_save($post, $attachment) {
if( isset($attachment['ime-autora']) ){
update_post_meta($post['ID'], '_ime-autora', $attachment['ime-autora']);
}
return $post;
}
add_filter("attachment_fields_to_save", "ime_autora_field_save", null , 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment