Ver Mensaje Individual
  #2 (permalink)  
Antiguo 17/05/2012, 13:41
Avatar de metacortex
metacortex
Viejo demente
 
Fecha de Ingreso: junio-2004
Ubicación: Caracas - Venezuela
Mensajes: 9.027
Antigüedad: 19 años, 10 meses
Puntos: 832
Respuesta: Problema: se borran valores custom post type

Cita:
Iniciado por damian.adriel Ver Mensaje
Tengo el siguiente problema, he creado un Custom Post Type, con un pequeño campo de texto para almacenar vaores.

Al precionar el botón publicar se guardan sin problemas en la base de datos.

Pero al transcurrir varios segundos se borran automaticamente. He probado con un codigo similar que suba imagenes y no hay problema.
El milagro es que con ese código puedas guardar algo. Errores de sintaxis, funciones sin la debida salida, etc.. O no has posteado el código completo, o estuviste probando otra cosa.

Prueba así:

Código PHP:
Ver original
  1. add_action( 'add_meta_boxes', 'admin_init' );
  2. add_action('save_post', 'save_texto');
  3. add_action( 'init', 'mis_noticias' );
  4.  
  5. function mis_noticias() {
  6.     $labels = array(
  7.         'name' => _x('Noticias', 'post type general name'),
  8.         'singular_name' => _x('Noticias', 'post type singular name'),
  9.         'add_new' => _x('Agregar Nueva', 'Noticia'),
  10.         'add_new_item' => __('Agregar Nueva Noticia'),
  11.         'edit_item' => __('Editar Noticias'),
  12.         'new_item' => __('Nuevo Noticia'),
  13.         'view_item' => __('Ver Noticia'),
  14.         'search_items' => __('Buscar Noticias'),
  15.         'not_found' =>  __('Nada encontrado'),
  16.         'not_found_in_trash' => __('Nada encontrado en papelera'),
  17.         'parent_item_colon' => ''
  18.     );
  19.  
  20.     $args = array(
  21.         'labels' => $labels,
  22.         'public' => true,
  23.         'publicly_queryable' => true,
  24.         'show_ui' => true,
  25.         'query_var' => true,
  26.         'rewrite' => true,
  27.         'capability_type' => 'post',
  28.         'hierarchical' => true,
  29.         'menu_position' => null,
  30.         'rewrite'   => array( 'slug' => 'auctions' ),
  31.         'has_archive' => true,
  32.         'supports' => array('title' , 'editor' , 'excerpt' , 'thumbnail' , 'comments' , 'author' , 'page-attributes')
  33.     );
  34.  
  35.     register_post_type( 'noticias' , $args );
  36. }
  37.  
  38. function admin_init(){
  39.     add_meta_box('texto' , 'Texto' , 'texto', 'noticias' , 'normal' , 'low');
  40. }
  41.  
  42. function texto(){
  43.     global $post;
  44.     $custom = get_post_custom($post->ID);
  45.     $contenido = isset($custom['contenido'][0]) ? $custom['contenido'][0] : null;
  46.     $salida = 'contenido: <input name="contenido" type="text" id="contenido" size="100" value="'. $contenido .'" />';
  47.     echo $salida;
  48. }
  49.  
  50. function save_texto(){
  51.     global $post;
  52.     update_post_meta($post->ID , 'contenido' , $_POST['contenido']);
  53. }