Skip to content

Instantly share code, notes, and snippets.

@ericandrewlewis
Created August 11, 2015 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericandrewlewis/44410f62d19117454b31 to your computer and use it in GitHub Desktop.
Save ericandrewlewis/44410f62d19117454b31 to your computer and use it in GitHub Desktop.
Testing extra attachment fields
<?php
function add_attachment_location_field( $form_fields, $post ) {
$field_value = get_post_meta( $post->ID, 'location', true );
$form_fields['location'] = array(
'value' => $field_value ? $field_value : '',
'label' => __( 'Location' ),
'helps' => __( 'Set a location for this attachment' )
);
return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'add_attachment_location_field', 10, 2 );
function save_attachment_location( $attachment_id ) {
if ( isset( $_REQUEST['attachments'][$attachment_id]['location'] ) ) {
$location = $_REQUEST['attachments'][$attachment_id]['location'];
update_post_meta( $attachment_id, 'location', $location );
}
}
add_action( 'edit_attachment', 'save_attachment_location' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment