일부 라디오 버튼에서 값을 선택하고 wordpress 데이터베이스의 post_meta 테이블에 저장할 수있는 사용자 정의 메타 상자를 만들었습니다. 다음 코드를 사용하여 값을 저장합니다.사용자 정의 메타 상자의 라디오 버튼을 선택하는 방법은 무엇입니까?
그러나 게시물을 다시 편집하려면 현재 값이있는 라디오 버튼이 선택되어 있어야합니다. 그렇게하는 가장 좋은 방법은 무엇입니까? 여기에 메타 상자를 표시하는 기능은 다음과 같습니다
function my_custom_meta_box($object, $box) {
$post_id=get_the_ID();
$key='my_key';
$the_value_that_should_be_set_to_checked=get_post_meta($post_id, $key);
//$the_value_that_should_be_set_to_checked[0] returns the value as string
?>
<label for="my_custom_metabox"><?php _e("Choose value:", 'choose_value'); ?></label>
<br />
<input type="radio" name="the_name_of_the_radio_buttons" value="value1">Value1<br>
<input type="radio" name="the_name_of_the_radio_buttons" value="value2">Value2<br>
<input type="radio" name="the_name_of_the_radio_buttons" value="value3">Value3<br>
<input type="radio" name="the_name_of_the_radio_buttons" value="value4">Value4<br>
<?php
}
내가 모든 라인에 if(isset($the_value_that_should_be_set_to_checked[0])=="value of that line") echo "checked='checked'";
같은 것을 쓸 수 있지만 나에게 매우 우아하지 않는 것 같습니다. 자바 스크립트를 사용하는 것은 워드 프레스에서 꽤 복잡하다. 왜냐하면 나는 후크를 사용해야하고, 스크립트를 큐에 넣고, 자바 스크립트의 한 줄로 체크 된 속성을 변경하기 때문에 가치가 없다. 가장 좋은 방법은 무엇입니까?
은 사용했던 액션 후크를 제공합니다. –
add_action ('load-post.php', 'my_custom_meta_box_setup'); add_action ('load-post-new.php', 'my_custom_meta_box_setup'); 및 setup 함수 내에서 : add_action ('add_meta_boxes', 'my_custom__meta_box'); 및 add_action ('save_post', 'save_value_of_my_custom_metabox', 10, 2); – user2718671