0
선택 옵션이있는 사용자 정의 게시 유형 중 하나에 대한 메타 상자를 만들고 있습니다. 게시물을 선택하고 업데이트 할 때 페이지가 다시로드 될 때 옵션이 계속 선택되도록하려고합니다. StackOverflow에서 같은 작업을하는 사람들이 몇 명 있었고 그 제안을 따랐지만 아직 이해하지 못했습니다. 누구든지 제안이 있다면, 어떤 도움을 주시면 감사하겠습니다.업데이트 후 선택을 유지하기 위해 메타 상자 가져 오기
<?php
function property_info_meta_box() {
add_meta_box('property-info', 'Property', 'property_info_cb', 'properties', 'normal', 'high');
}
add_action('add_meta_boxes', 'property_info_meta_box');
function property_info_cb($propertyInfo) {
$selectAgent = get_post_meta($propertyInfo->ID, 'select-agent-value', true);
?>
<label for="select-agent-text">Select Agent</label> <br>
<select multiple size="5" name="select-agent" id="select-agent">
<option value="none">None</option>
<?php
$args = array(
'post_type' => 'agents',
'posts_per_page' => -1
);
$posts = new WP_Query($args);
if ($posts->have_posts()) : while ($posts->have_posts()) : $posts->the_post(); ?>
<option value="<?php the_ID() ?>" <?php selected($selectAgent, the_ID()); ?>> <?php the_title(); ?> </option>
<?php endwhile; endif; ?>
</select>
<?php }
function add_property_info_fields ($propertyInfoId, $propertyInfo){
if ($propertyInfo->post_type == 'properties') {
if(isset($_POST['select-agent'])){
update_post_meta($propertyInfoId, 'select-agent-value', $_POST['select-agent']);
}
}
}
add_action('save_post', 'add_property_info_fields', 10, 2);
대 get_the_ID()하세요! 너 락! –