Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WP - register custom field for media
<?php
function be_attachment_field_credit( $form_fields, $post ) {
//
// ---- CS ---
//
$form_fields['media_date'] = array(
'label' => 'Datum',
'input' => 'text',
'value' => get_post_meta( $post->ID, 'media_date', true ),
// 'helps' => 'datace',
);
return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'be_attachment_field_credit', 10, 2 );
/**
* Save media values
*
* @param $post array, the post data for database
* @param $attachment array, attachment fields from $_POST form
* @return $post array, modified post data
*/
function be_attachment_field_credit_save( $post, $attachment ) {
if( isset( $attachment['media_date'] ) )
update_post_meta( $post['ID'], 'media_date', esc_attr( $attachment['media_date'] ) );
return $post;
}
add_filter( 'attachment_fields_to_save', 'be_attachment_field_credit_save', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.