WordPerformer 플러그인 용 데이터 테이블에 데이터를 삽입하고 싶습니다. POST로 데이터를 가져옵니다. 나는 (게시물과 함께 찍은) 여러 개의 결과를 가지고 있지만, $ wpdb-> insert는 오직 나에게 마지막 결과를 삽입한다 (실제적으로 데이터를 덮어 쓴다). 그게 왜? 여기 Wordpress는 여러 행을 데이터 테이블에 삽입합니다.
내 코드입니다 :HTML : 내가 위해 무엇을 할 수
echo '<label for="reduceri-post-category"><b>' . __("What categories should be the adverts", 'appplugin') . '</b></label><br /><br /><br />';
?>
<?php foreach ($the_data[categories] as $sat): ?>
<b> <?= $sat[name]; ?> <br /> </b>
<?php foreach ($sat[subcategories] as $cat):
?>
<input type="checkbox" name="reduceri-post-category" value="<?= $cat[sid] ?>" /> <?php echo $cat[name]; echo $cat[sid]; ?><br />
<? endforeach; ?>
<? endforeach; ?>
global $wpdb;
$thedata['reduceri-post-category'] = $_POST['reduceri-post-category'];
$table_name = $wpdb->prefix . "reduceri";
foreach ($thedata as $key => $value) {
if($post->post_type == 'revision') return;
if ($post->post_type == 'post'){
$wpdb->insert($table_name, array('time' => current_time('mysql'), 'post' => $post->ID, 'category' => $value));
}
}
이 모든 결과뿐만 아니라 마지막을 삽입 할 수 있도록? 고마워요!
코드를 간략하게 살펴보면 코드가 한 번만 삽입되지만 여러 번 삽입되지는 않습니다. 그리고 코드에 적절한 들여 쓰기가 도움이 될 수 있습니다. – hakre