지역 리그를위한 매우 간단한 커스텀 플러그인을 개발 중입니다. 팀 플레이어와 선수를 순위와 비품과 함께 관리 할 수있는 무언가가 필요합니다. post_type, meta_box 및 taxonomy 함수를 사용하여 플러그인을 개발할 계획입니다. 저는 전문가는 아니지만 기능의 기본 사용법을 알고 있습니다. 나는 팀의 서있는 속성을 채우기 위해 백엔드에 표시된 여러 입력이 필요한 지점에 갇혀있다. 승, 무승부, 손실, 포인트 등. 필드를 관리자 패널에 표시 할 수있게 만들었지 만 하나의 입력 필드 데이터를 저장할 수있는 방법을 알고 있지만 몇 가지 데이터가 있기 때문에 내가 아는 거의 모든 방법과 많은 사이트를 시도했지만 얻을 수는 없었습니다. 그들은 구원 받았다. 나는 성공적으로이 코드에 의해 하나 개의 입력 필드 데이터를 저장할 수 있습니다wordpress에서 custom_meta_box를 통해 여러 입력 값을 저장하는 방법은 무엇입니까?
코드를 살펴, 제발
<?php
/*
Plugin Name: Manage Clubs
Plugin URI: https://www.odesk.com/users/~01a9f6045443021f0c
Description: A simple lightweight plugin to manage your legue.
Author: Abubakkar Roby
Author URI: https://www.odesk.com/users/~01a9f6045443021f0c
Version: 1.0
*/
class RN_Manage_Clubs {
public function __construct() {
$this->register_post_type();
$this->statistics();
}
public function register_post_type() {
$args = array(
'labels' => array(
'name' => 'Manage Clubs',
'all_items' => 'Clubs',
'singular_name' => 'Club',
'add_new' => 'Add New Club',
'add_new_item' => 'Add New Club',
'edit_item' => 'Edit Club',
'new_item' => 'Add New Item',
'view_item' => 'View Club',
'search_items' => 'Search Clubs',
'not_found' => 'No Clubs Found',
'not_found_in_trash' => 'No Clubs Found In Trash'
),
'query_var' => 'Clubs',
'rewrite' => array('slug' => 'clubs/'),
//'menu_position' => 5,
'menu_icon' => admin_url() . 'images/icon_soccer.png',
'supports' => ['title', 'thumbnail'],
'public' => true
);
register_post_type('RN_Manage_Clubs', $args);
}
public function statistics() {
add_action('add_meta_boxes', function() {
//css id, title, cb func, assoc. page/post, priority, cb func args
add_meta_box('rn_club_stat', 'Club Standing', 'club_stats', 'RN_Manage_Clubs');
});
function club_stats($post) {
$POS = get_post_meta($post->ID, 'rn_club_stat', true);
?>
<input type="text" name="rn_club_stat" id="rn_club_stat" value="<?php echo esc_attr($POS); ?>" size="1" tabindex="-1" />
<?php
}
add_action('save_post', function($id) {
if(isset($_POST['rn_club_stat'])) {
update_post_meta(
$id,
'rn_club_stat',
strip_tags($_POST['rn_club_stat'])
);
}
});
}
}
add_action('init', function() {
new RN_Manage_Clubs();
});
하지만 이러한 필드처럼 여러 개의 입력 필드에서 데이터를 저장 어떻게
<?php
/*
Plugin Name: Manage Clubs
Plugin URI: https://www.odesk.com/users/~01a9f6045443021f0c
Description: A simple lightweight plugin to manage your legue.
Author: Abubakkar Roby
Author URI: https://www.odesk.com/users/~01a9f6045443021f0c
Version: 1.0
*/
class RN_Manage_Clubs {
public function __construct() {
$this->register_post_type();
$this->statistics();
}
public function register_post_type() {
$args = array(
'labels' => array(
'name' => 'Manage Clubs',
'all_items' => 'Clubs',
'singular_name' => 'Club',
'add_new' => 'Add New Club',
'add_new_item' => 'Add New Club',
'edit_item' => 'Edit Club',
'new_item' => 'Add New Item',
'view_item' => 'View Club',
'search_items' => 'Search Clubs',
'not_found' => 'No Clubs Found',
'not_found_in_trash' => 'No Clubs Found In Trash'
),
'query_var' => 'Clubs',
'rewrite' => array('slug' => 'clubs/'),
//'menu_position' => 5,
'menu_icon' => admin_url() . 'images/icon_soccer.png',
'supports' => ['title', 'thumbnail'],
'public' => true
);
register_post_type('RN_Manage_Clubs', $args);
}
public function statistics() {
add_action('add_meta_boxes', function() {
//css id, title, cb func, assoc. page/post, priority, cb func args
add_meta_box('rn_club_stat', 'Club Standing', 'club_stats', 'RN_Manage_Clubs');
});
function club_stats($post) {
$POS = get_post_meta($post->ID, 'rn_club_stat', true);
?>
<table>
<thead>
<tr>
<td> </td>
<th>POS</th>
<th>W</th>
<th>D</th>
<th>L</th>
<th>F</th>
<th>A</th>
<th>GD</th>
<th>PTS</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Total</th>
<td><input type="text" name="POS" value="" size="1" tabindex="-1" readonly /></td>
<td><input type="text" name="W" value="" size="1" tabindex="-1" readonly /></td>
<td><input type="text" name="D" value="" size="1" tabindex="-1" readonly /></td>
<td><input type="text" name="L" value="" size="1" tabindex="-1" readonly /></td>
<td><input type="text" name="F" value="" size="1" tabindex="-1" readonly /></td>
<td><input type="text" name="A" value="" size="1" tabindex="-1" readonly /></td>
<td><input type="text" name="GD" value="" size="1" tabindex="-1" readonly /></td>
<td><input type="text" name="PTS" value="" size="1" tabindex="-1" readonly /></td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Values</td>
<td><input type="text" name="POS" id="POS" value="" size="1" tabindex="-1" /></td>
<td><input type="text" name="W" value="" size="1" tabindex="-1" /></td>
<td><input type="text" name="D" value="" size="1" tabindex="-1" /></td>
<td><input type="text" name="L" value="" size="1" tabindex="-1" /></td>
<td><input type="text" name="F" value="" size="1" tabindex="-1" /></td>
<td><input type="text" name="A" value="" size="1" tabindex="-1" /></td>
<td><input type="text" name="GD" value="" size="1" tabindex="-1" /></td>
<td><input type="text" name="PTS" value="" size="1" tabindex="-1" /></td>
</tr>
</tbody>
</table>
<?php
}
add_action('save_post', function($id) {
if(isset($_POST['rn_club_stat'])) {
update_post_meta(
$id,
'rn_club_stat',
strip_tags($_POST['rn_club_stat'])
);
}
});
}
}
add_action('init', function() {
new RN_Manage_Clubs();
});
@gorirrajoe, get_post_custom() 함수를 사용하여 그 해결책을 찾았습니다. 그러나 나는 당신의 코드도 시도 할 것입니다. 는 여기에 코드는 "rn_club_stat"가 설정되어 있는지 찾고 나를
<?php
/*
Plugin Name: Manage League
Plugin URI: https://www.odesk.com/users/~01a9f6045443021f0c
Description: A simple lightweight plugin to manage your legue.
Author: Abubakkar Roby
Author URI: https://www.odesk.com/users/~01a9f6045443021f0c
Version: 1.0
*/
class RN_Manage_Clubs {
public function __construct() {
$this->register_post_type();
$this->statistics();
}
public function register_post_type() {
$args = array(
'labels' => array(
'name' => 'Manage Clubs',
'all_items' => 'Clubs',
'singular_name' => 'Club',
'add_new' => 'Add New Club',
'add_new_item' => 'Add New Club',
'edit_item' => 'Edit Club',
'new_item' => 'Add New Item',
'view_item' => 'View Club',
'search_items' => 'Search Clubs',
'not_found' => 'No Clubs Found',
'not_found_in_trash' => 'No Clubs Found In Trash'
),
'query_var' => 'Clubs',
'rewrite' => array('slug' => 'clubs/'),
//'menu_position' => 5,
'menu_icon' => admin_url() . 'images/icon_soccer.png',
'supports' => ['title', 'editor', 'thumbnail'],
'public' => true
);
register_post_type('RN_Manage_Clubs', $args);
}
public function statistics() {
add_action('add_meta_boxes', function() {
//css id, title, cb func, assoc. page/post, priority, cb func args
add_meta_box('rn_club_stat', 'Club Standing', 'club_stats', 'RN_Manage_Clubs');
});
function club_stats($post) {
//$value = get_post_meta($post->ID, 'rn_club_stat', false);
global $post;
$custom = get_post_custom($post->ID);
$POS = $custom['POS'][0];
$P = $custom['P'][0];
$W = $custom['W'][0];
$D = $custom['D'][0];
$L = $custom['L'][0];
$B = $custom['B'][0];
$PTS = $custom['PTS'][0];
?>
<table>
<thead>
<tr>
<td> </td>
<th>POS</th>
<th>P</th>
<th>W</th>
<th>D</th>
<th>L</th>
<th>B</th>
<th>PTS</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Total</th>
<td><input type="text" name="POS" id="POS" value="<?php echo $POS; ?>" size="1" tabindex="-1" readonly /></td>
<td><input type="text" name="P" id="P" value="<?php echo $P; ?>" size="1" tabindex="-1" readonly /></td>
<td><input type="text" name="W" value="<?php echo $W; ?>" size="1" tabindex="-1" readonly /></td>
<td><input type="text" name="D" value="<?php echo $D; ?>" size="1" tabindex="-1" readonly /></td>
<td><input type="text" name="L" value="<?php echo $L; ?>" size="1" tabindex="-1" readonly /></td>
<td><input type="text" name="F" value="<?php echo $B; ?>" size="1" tabindex="-1" readonly /></td>
<td><input type="text" name="PTS" value="<?php echo $PTS; ?>" size="1" tabindex="-1" readonly /></td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Values</td>
<td><input type="text" name="POS" id="POS" value="<?php echo $POS; ?>" size="1" tabindex="-1" /></td>
<td><input type="text" name="P" id="P" value="<?php echo $P; ?>" size="1" tabindex="-1" /></td>
<td><input type="text" name="W" id="W" value="<?php echo $W; ?>" size="1" tabindex="-1" /></td>
<td><input type="text" name="D" value="<?php echo $D; ?>" size="1" tabindex="-1" /></td>
<td><input type="text" name="L" value="<?php echo $L; ?>" size="1" tabindex="-1" /></td>
<td><input type="text" name="B" value="<?php echo $B; ?>" size="1" tabindex="-1" /></td>
<td><input type="text" name="PTS" value="<?php echo $PTS; ?>" size="1" tabindex="-1" /></td>
</tr>
</tbody>
</table>
<?php
}
add_action('save_post', function($id) {
if(isset($_POST['POS'])) {
update_post_meta($id,'POS', $_POST['POS']);
}
if(isset($_POST['P'])) {
update_post_meta($id,'P', $_POST['P']);
}
if(isset($_POST['W'])) {
update_post_meta($id,'W', $_POST['W']);
}
if(isset($_POST['D'])) {
update_post_meta($id,'D', $_POST['D']);
}
if(isset($_POST['L'])) {
update_post_meta($id,'L', $_POST['L']);
}
if(isset($_POST['B'])) {
update_post_meta($id,'B', $_POST['B']);
}
if(isset($_POST['PTS'])) {
update_post_meta($id,'PTS', $_POST['PTS']);
}
});
}
}
add_action('init', function() {
new RN_Manage_Clubs();
});
제발 무슨 코드가 좋을까요? 내가 그들을 어디에 두어야합니까? – satancorpse
한 가지 질문 - '총'셀에 무엇이 들어 있습니까? – gorirrajoe
질문과 설명을 다시 확인하십시오. 주석 상자에 스 니펫을 게시 할 수 없으므로 업데이트했습니다. 총 셀은 동일한 값을 가지며 사용자가 입력 할 수 없도록 표시 할 수 있도록 속성을 비활성화합니다. @gorirrajoe – satancorpse