The main problem is you’re not echoing names of your fields. Like <input type="text" name="<? 'jugador_' . $contador ?>"
should be <input type="text" name="<? echo 'jugador_' . $contador ?>"
Still, I have a better suggestion. You can use arrays in your form submission. So your metabox callback function should look like this:
function mock_metabox() {
global $post;
// Nonce field
wp_nonce_field( basename( __FILE__ ), 'mock_fields' );
// init counter for meta array
$selecciones = get_post_meta( $post->ID, '_seleccion', true );
$equipos = get_post_meta( $post->ID, '_equipo', true );
$equiposog = get_post_meta( $post->ID, '_equipoog', true );
// Output the fields
?>
<h3> Informacion del Mock </h3>
<table>
<tr>
<th> # </th>
<th> Jugador </th>
<th> Equipo </th>
<th> Equipo Original </th>
</tr>
<?
$contador = 1;
$teams = get_posts( array(
'post_type' => 'team',
'orderby' => 'title',
'order' => 'ASC',
'numberposts' => -1,
'post_status' => 'publish'
) );
while ( $contador <= 60 ){
$v_jugador = isset( $selecciones[$contador-1] ) ? $selecciones[$contador-1] : '';
$v_equipo = isset( $equipos[$contador-1] ) ? $equipos[$contador-1] : '';
$v_equiposog = isset( $equiposog[$contador-1] ) ? $equiposog[$contador-1] : '';
?>
<tr>
<td><?php echo $contador ?></td>
<td><input type="text" name="jugador[]" value="<?php echo $v_jugador; ?>" />
<td><select name="equipo[]"><?
foreach ( $teams as $team ) { ?>
<option value="<?php echo $team->ID; ?>" <?php selected( $v_equipo, $team->ID ); ?> > <?php echo $team->post_title; ?> </option> <? } ?> </select> </td>
<td><select name="equipoog[]"><?
foreach ( $teams as $team ) { ?>
<option value="<?php echo $team->ID; ?>" <?php selected( $v_equiposog, $team->ID ); ?> > <?php echo $team->post_title; ?> </option> <? } ?> </select> </td>
<? $contador++; ?>
</tr>
<?php } ?>
</table>
<?
}
And the updating function to this:
function mock_save_meta_box_data( $post_id ){
// verify taxonomies meta box nonce
if ( !isset( $_POST['mock_fields'] ) || !wp_verify_nonce( $_POST['mock_fields'], basename( __FILE__ ) ) ){
return;
}
// return if autosave
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){
return;
}
// Check the user's permissions.
if ( ! current_user_can( 'edit_post', $post_id ) ){
return;
}
// guarda tipo traspaso
if ( isset( $_POST['jugador'] ) ) {
update_post_meta( $post_id, '_seleccion', $_POST['jugador'] );
}
if ( isset( $_POST['jugador'] ) ) {
update_post_meta( $post_id, '_equipo', $_POST['equipo'] );
}
if ( isset( $_POST['jugador'] ) ) {
update_post_meta( $post_id, '_equipoog', $_POST['equipoog'] );
}
add_action( 'save_post_mock', 'mock_save_meta_box_data' );
Give it a try.
Edit: Don’t use checked()
in select field’s options. Use selected()
function.