나는 워드 프레스 테마를 개발 중이다. 두 가지 맞춤 게시 유형 (교사 및 코스)을 등록했으며 그 중 하나 (코스)에 몇 가지 메타 복스를 추가했습니다.메타 박스 - 체크 박스와 텍스트 함께.
두 개는 텍스트 입력 대사이며 잘 작동합니다 (값은 게시시 저장됩니다).
이제 다른 맞춤 게시물 유형 (교사)의 모든 게시물의 제목과 ID를 검색하는 몇 가지 체크 박스를 추가하고 싶습니다. 요점은 특정 코스와 관련된 교사 (또는 교사)를 확보 할 수 있다는 것입니다. 사용자는 주어진 코스를 가르치는 교사의 이름을 상자에 표시합니다.
지금까지 체크 박스를 표시했지만 지금은 데이터가 저장되지 않았습니다.
이는 지금 모습입니다 :
function wpt_languagecourses_location() {
global $post;
// Noncename needed to verify where the data originated
echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' .
wp_create_nonce(plugin_basename(__FILE__)) . '" />';
// Get the location data if its already been entered
$location = get_post_meta($post->ID, '_location', true);
$dresscode = get_post_meta($post->ID, '_dresscode', true);
// Echo out the field
echo '<p>Course price</p>';
echo '<input type="text" name="_location" value="' . $location . '" class="widefat" />';
echo '<p>How long will the course last?</p>';
echo '<input type="text" name="_dresscode" value="' . $dresscode . '" class="widefat" />';?>
<?php
$args = array('post_type' => 'teachers');
$loop = new WP_Query($args);
?>
<p>
<span class="prfx-row-title">Who is the teacher?</span>
<div class="prfx-row-content">
<?php while ($loop->have_posts()) : $loop->the_post();?>
<label for="meta-checkbox">
<input type="checkbox" name="meta-checkbox" id="meta-checkbox" value="yes" <?php if (isset ($prfx_stored_meta['meta-checkbox'])) checked($prfx_stored_meta['meta-checkbox'][0], 'yes'); ?> />
<?php the_title() ?>
</label>
<?php endwhile; ?>
</div>
</p>
<?php }
// Add the Events Meta Boxes
function add_languagecourses_metaboxes() {
add_meta_box('wpt_languagecourses_location', 'Languagecourses Location', 'wpt_languagecourses_location', 'languagecourses', 'side', 'default');
}
// Save the Metabox Data
function wpt_save_languagecourses_meta($post_id, $post) {
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if (!wp_verify_nonce($_POST['eventmeta_noncename'], plugin_basename(__FILE__))) {
return $post->ID;
}
// Is the user allowed to edit the post or page?
if (!current_user_can('edit_post', $post->ID))
return $post->ID;
// OK, we're authenticated: we need to find and save the data
// We'll put it into an array to make it easier to loop though.
$languagecourses_meta['_location'] = $_POST['_location'];
$languagecourses_meta['_dresscode'] = $_POST['_dresscode'];
// Add values of $events_meta as custom fields
foreach ($languagecourses_meta as $key => $value) { // Cycle through the $events_meta array!
if($post->post_type == 'revision') return; // Don't store custom data twice
$value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
update_post_meta($post->ID, $key, $value);
} else { // If the custom field doesn't have a value
add_post_meta($post->ID, $key, $value);
}
if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
}
}
// Checks for input and saves
add_action('save_post', 'wpt_save_languagecourses_meta', 1, 2); // save the custom fields
가 어떻게 사용자가이를 확인하는 체크 박스의 데이터를 저장할 수 있습니까?