Ver Mensaje Individual
  #3 (permalink)  
Antiguo 25/02/2013, 10:28
Avatar de zanguanga
zanguanga
Moderadora
 
Fecha de Ingreso: julio-2009
Ubicación: España
Mensajes: 1.686
Antigüedad: 14 años, 9 meses
Puntos: 429
Respuesta: 1a foto en volcado de posts por categorias funciona a lo loco

A diferencia de otros códigos similares a mí sí me funciona este, sin embargo hay algún error.

Código PHP:
Ver original
  1. function auto_post_thumbnail() {
  2.           global $post;
  3.           $already_has_thumb = has_post_thumbnail($post->ID);
  4.               if (!$already_has_thumb)  {
  5.               $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
  6.                           if ($attached_image) {
  7.                                 foreach ($attached_image as $attachment_id => $attachment) {
  8.                                 set_post_thumbnail($post->ID, $attachment_id);
  9.                                 }
  10.                            } else {
  11.                                 set_post_thumbnail($post->ID, 'ID_imagen_por_defecto');
  12.                            }
  13.                         }
  14.       }
  15.  //Final de la función
  16. add_action('the_post', 'auto_post_thumbnail');
  17. add_action('save_post', 'auto_post_thumbnail');
  18. add_action('draft_to_publish', 'auto_post_thumbnail');
  19. add_action('new_to_publish', 'auto_post_thumbnail');
  20. add_action('pending_to_publish', 'auto_post_thumbnail');
  21. add_action('future_to_publish', 'auto_post_thumbnail');

Sin embargo al activar el debug salta esto cuando guardo un menú nuevo
Cita:
Notice: Trying to get property of non-object in ruta-tema-tema/functions.php líneas 3, 5 y 8
¿?
__________________
Mi blog personal | Mi G+

Última edición por zanguanga; 25/02/2013 a las 12:30