1
이미지 첨부 파일에 대해 다음과 같은 메타 데이터 옵션을 만들었습니다. 기본적으로 사용자는 라디오 버튼을 선택합니다. 그런 다음 적절한 클래스가 div에 추가됩니다. div는 첨부 파일을 래핑합니다. 어떤 이유로 든 선택한 라디오 버튼 값이 저장되지 않습니다. 그러나 입력을 일반 텍스트 필드로 전환하면 모든 것이 완벽하게 작동한다는 것을 알았습니다.라디오 버튼을 사용할 때 첨부 파일 메타 데이터가 저장되지 않음
function add_attachment_classes_field($form_fields, $post) {
$field_value = get_post_meta($post->ID, 'classes', true);
$form_fields['classes'] = array(
'value' => $field_value ? $field_value : '',
'label' => __('Classes'),
'input' => 'html',
'html' => "<div><input checked='checked' style='width: initial' type='radio' name='border-style' value=''> None</div>
<div><input style='width: initial' type='radio' name='border-style' value='green-border'> Green</div>
<div><input style='width: initial' type='radio' name='border-style' value='red-border'> Red</div>
<div><input style='width: initial' type='radio' name='border-style' value='jagged-border'> Jagged</div>
<div><input style='width: initial' type='radio' name='border-style' value='purple-border'> Purple</div>",
);
return $form_fields;
}
function save_attachment_classes($attachment_id) {
if (isset($_REQUEST['attachments'][$attachment_id]['classes'])) {
$classes = $_REQUEST['attachments'][$attachment_id]['classes'];
update_post_meta($attachment_id, 'classes', $classes);
}
}
function wrap_my_div($html, $id, $caption, $title, $align, $url, $size, $alt) {
$field_value = get_post_meta($id, 'classes', true);
return '<div class="'.$field_value.'">'.$html.'</div>';
}
add_action('edit_attachment', 'save_attachment_classes');
add_filter('attachment_fields_to_edit', 'add_attachment_classes_field', 10, 2);
add_filter('image_send_to_editor', 'wrap_my_div', 10, 8);
합니다. 페이지를 새로 고침 할 때 다른 값을 선택하여 저장하더라도 첫 번째 값이 표시됩니다. 'checked()'함수를 살펴 보자. http://codex.wordpress.org/Function_Reference/checked –