Select field on feature image metabox
/**
* Select field on featured image
*
*/
add_filter( 'admin_post_thumbnail_html', function ( $content, $post_id ) {
$field_opt = '';
$field_id = '_content_bg_position';
$field_value = esc_attr( get_post_meta( $post_id, $field_id, true ) );
$field_text = __('Background Position');
$field_var = array('', 'center', 'top', 'bottom');
var_dump($field_value);
foreach ($field_var as $item)
$field_opt .= sprintf('<option value="%1$s"%2$s>%1$s</option>', $item, selected( $field_value, $item, false));
$field_label = sprintf(
'<p><label for="%1$s">%2$s</label><br /><select name="%1$s" id="%1$s">%3$s</select></p>',
$field_id, $field_text, $field_opt
);
return $content .= $field_label;
}, 10, 2 );
add_action( 'save_post', function ( $post_ID, $post, $update ) {
$field_id = '_content_bg_position';
$field_value = isset( $_REQUEST[ $field_id ] ) ? $_REQUEST[ $field_id ] : 0;
update_post_meta( $post_ID, $field_id, $field_value );
}, 10, 3 );