Foros del Web » Creando para Internet » Sistemas de gestión de contenidos » WordPress »

Problema: se borran valores custom post type

Estas en el tema de Problema: se borran valores custom post type en el foro de WordPress en Foros del Web. Hola: 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 ...
  #1 (permalink)  
Antiguo 17/05/2012, 07:36
Avatar de damian.adriel  
Fecha de Ingreso: junio-2007
Mensajes: 35
Antigüedad: 16 años, 10 meses
Puntos: 0
Problema: se borran valores custom post type

Hola:

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.

Porque puede ser el problema ?. Aqui copio mi código:

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

Muchas gracias, espero me puedan ayudar.
  #2 (permalink)  
Antiguo 17/05/2012, 13:41
Avatar de 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. }
  #3 (permalink)  
Antiguo 17/05/2012, 14:42
Avatar de damian.adriel  
Fecha de Ingreso: junio-2007
Mensajes: 35
Antigüedad: 16 años, 10 meses
Puntos: 0
Respuesta: Problema: se borran valores custom post type

http://codex.wordpress.org/Post_Types#Custom_Types
  #4 (permalink)  
Antiguo 17/05/2012, 14:54
Avatar de 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
http://codex.wordpress.org/Post_Types#Custom_Types
¿Qué quieres decir con esto?.

¿Lograste o no solucionarlo con el código que te di?. Reemplaza el antiguo por ese y haz pruebas.
  #5 (permalink)  
Antiguo 17/05/2012, 14:56
Avatar de damian.adriel  
Fecha de Ingreso: junio-2007
Mensajes: 35
Antigüedad: 16 años, 10 meses
Puntos: 0
Respuesta: Problema: se borran valores custom post type

O sea,

el codigo si funciona, esto se incluye en el functions.php del tema. lo que no se pq los datos se almacenan por solo unos segundos o no se si se borren por al auto-save.

saludos
  #6 (permalink)  
Antiguo 18/05/2012, 22:22
Avatar de damian.adriel  
Fecha de Ingreso: junio-2007
Mensajes: 35
Antigüedad: 16 años, 10 meses
Puntos: 0
Respuesta: Solucionado

Efectivamente, el problema estaba en el autosave.

para solucinarlo, basta con 2 lineas:

function save_texto(){
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;


global $post;
update_post_meta($post->ID, "contenido", $_POST["contenido"]);
}

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:54.