I have created the follow code in functions.php to add custom fields to attachments media library. Data saves as well, but I can't get data to display into the template file. Any suggestion??
Thanks!
function mytheme_attachment_fields( $fields, $post ) { $meta = get_post_meta($post->ID, 'title_en', true); $fields['title_en'] = array( 'label' => 'Título (EN)', 'input' => 'text', 'value' => $meta, 'show_in_edit' => true, ); return $fields;
} add_filter( 'attachment_fields_to_edit', 'mytheme_attachment_fields', 10, 2 );
function mytheme_update_attachment_meta($attachment){ global $post; update_post_meta($post->ID, 'custom_title', $attachment['attachments'][$post->ID]['custom_title']);
} add_filter( 'edit_attachment', 'mytheme_update_attachment_meta', 4);
function mytheme_media_xtra_fields() { $post_id = $_POST['id']; $meta = $_POST['attachments'][$post_id ]['custom_title']; update_post_meta($post_id , 'custom_title', $meta); clean_post_cache($post_id); } add_action('wp_ajax_save-attachment-compat', 'mytheme_media_xtra_fields', 0, 1);
Aucun commentaire:
Enregistrer un commentaire