Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/01/2015, 11:03
Avatar de satanson123
satanson123
 
Fecha de Ingreso: julio-2012
Mensajes: 217
Antigüedad: 11 años, 9 meses
Puntos: 2
custom field dinamico

Hola amigos tengo un trabajo nuevo que lleba customs fields, les dejo una captura de lo que se necesita mas o menos:



Aqui abajo les dejor el codigo con el cual cree esto, talvez puedan editar y nos sea mas facil arregrarlo.

Código PHP:
//Custom fields

add_action('admin_init', 'online_add_custom_box', 1);
function online_add_custom_box() {
    add_meta_box( 
        'id_online',
        'Enlaces Online',
        'wp_box_online',
        'post'
    );
}

function wp_box_online($post) {
wp_nonce_field(plugin_basename(__FILE__), 'online_noncename');
if($_GET['action']=='edit'){
$enlace=get_post_meta($post->ID,'enlace',true);
$idioma=get_post_meta($post->ID,'idioma',true);
$calidad=get_post_meta($post->ID,'calidad',true);
?>
<table style="margin:0;padding:0;text-align:left;">
  <tr>
    <td>Enlace<br />
    <label style="border:1px solid #CCC;padding:5px;">Forosdelweb.com</label>

    <td>Idioma<br />
    <label style="border:1px solid #CCC;padding:5px;">Ingles</label>

    </td>
    <td>Calidad<br />
    <label style="border:1px solid #CCC;padding:5px;">DVDRip</label> <button>Elimnar</button>
</td>
  </tr>
</table>

<br /><br />
<table style="margin:0;padding:0;text-align:left;">
  <tr>
    <td>Enlace<br />
<input name="enlace" type="text" value="" class="regular-text" /></td>
    <td>Idioma<br />
    <select name="idioma" form="idioma">
    <option value="">Seleccione</option>
  <option value="es">Español</option>
  <option value="en">Ingles</option>
  <option value="lat">Español Latino</option>
</select>
    </td>
    <td>Calidad<br />
    <select name="calidad" form="calidad">
    <option value="">Seleccione</option>
  <option value="dvdrip">DVDRip</option>
  <option value="bdrip">BDRip</option>
  <option value="cam">CAM</option>
</select></td>
<td><button>Agregar</button></td>
  </tr>
</table>

<?php
}
}

add_action('save_post''guardar_online');

function 
guardar_online($post_id){
  if ( !
wp_verify_nonce$_POST['online_noncename'], plugin_basename(__FILE__) ) )
      return 
$post_id;

  if ( 
defined('DOING_AUTOSAVE') && DOING_AUTOSAVE 
      return 
$post_id;

    
  if ( !
current_user_can'edit_post'$post_id ) )
        return 
$post_id;
  
delete_post_meta($post_id'enlace');
if(!empty(
$_POST['enlace'])){
  
add_post_meta($post_id'enlace'esc_attr($_POST['enlace']));
}
delete_post_meta($post_id'idioma');
if(!empty(
$_POST['idioma'])){
  
add_post_meta($post_id'idioma'esc_attr($_POST['idioma']));
}
delete_post_meta($post_id'calidad');
if(!empty(
$_POST['calidad'])){
  
add_post_meta($post_id'calidad'esc_attr($_POST['calidad']));
}
  
}
Y que en el themes se muestre en una tabla.

La verdad me urge.

Última edición por satanson123; 26/01/2015 a las 11:10