I made custom post type "Collections" and I populate every post through featured image. Now I need to link every featured image to appropriate external link. So far I managed to add meta box to media uploader with this piece of code in functions.php
:
function be_attachment_field_credit( $form_fields, $post ) {
$form_fields['be-url'] = array(
'label' => 'URL',
'input' => 'text',
'value' => get_post_meta( $post->ID, 'be_url', true ),
'helps' => 'Add URL',
);
return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'be_attachment_field_credit', 10, 2 );
function be_attachment_field_credit_save( $post, $attachment ) {
if( isset( $attachment['be-url'] ) )
update_post_meta( $post['ID'], 'be_url', esc_url( $attachment['be-url'] ) );
return $post;
}
add_filter( 'attachment_fields_to_save', 'be_attachment_field_credit_save', 10, 2 );
And then in my single.php I add
echo get_post_meta(get_post_thumbnail_id(), 'be_url', true);
Now, when I click on featured image in admin panel in order to populate the meta box with url (for example http://www.google.com), the metabox saves the link, but when I go to my page where my featured image is, the featured image is not linked at all. How do i make my featured image go to external link? Thanx.