Disculpen la demora. Me había olvidado de pasar a agradecer. Todo resultó de maravillas. Básicamente utilicé esta función:
Código PHP:
Ver originalfunction insert_attachment($file_handler,$post_id,$setthumb='false') {
// check to make sure its a successful upload
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$attach_id = media_handle_upload( $file_handler, $post_id );
if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id);
// Update the post into the database
$my_post['ID'] = $attach_id;
$my_post['post_title'] = $_POST['titulo'];
$my_post['post_content'] = $_POST['comentario'];
wp_update_post( $my_post );
return $attach_id;
}//function insert_attachment
// código innecesario de mostrar
if ($_FILES['file']['error'] == 0 && $_POST['titulo'] != '') {
$filetype = wp_check_filetype
(basename($_FILES['file']['name']), null );
//echo $filetype['type']; exit;
if($filetype['type'] != 'image/jpeg'){
$fan_errores = true;
$fan_mensaje = '<p>Sólo imágenes JPG por favor.</p>';
}
else{
$post_id = 474;
foreach ($_FILES as $file => $array) {
$newupload = insert_attachment($file,$post_id);
// $newupload returns the attachment id of the file that
// was just uploaded. Do whatever you want with that now.
$from = get_option('admin_email');
$headers = 'From: '.$from . "\r\n";
$subject = "Nueva fan foto subida";
$msg = "Han subido una fan foto.\nLuego modifico este email para dar más datos.";
}//foreach
header("Location: /fan-fotos/?gracias"); }//
}
else{
$fan_errores = true;
$fan_mensaje = '<p>Seguramente te olvidaste de elegir tu foto o tal vez de escribir un título. Dale de nuevo.</p>';
}//if ($_FILES['file']['error'] == 0 && $_POST['titulo'] != '')
// código innecesario de mostrar
Luego muestro 6 fotos aleatorias:
Código PHP:
Ver originalfunction get_random_gallery_images(){
global $wpdb,$post;
$ids = "";
$counter = 0;
$number_of_posts = 6;
'post_type' => 'attachment',
'numberposts' => $number_of_posts,
'post_status' => null,
'orderby' => 'rand',
'meta_key' => '_mySelectBox',
'meta_value' => 'fanfoto_aprobada',
'post_parent' => 474
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
if ($counter != 0) {
$ids .= ','.$attachment->ID;
}
else {
$ids .= $attachment->ID;
}
$counter++;
}
}
return $ids;
}
$attachment_ids = get_random_gallery_images();
//echo $attachment_ids;
$fanfotos = new WP_Query('pagename=fan-fotos&showposts=1');
while ($fanfotos->have_posts()) : $fanfotos->the_post();
// echo get_the_content();
echo do_shortcode('[gallery link="file" size="fan_fotos_thumb" include="'.$attachment_ids.'" orderby="rand" columns="0"]');
endwhile; //$fanfotos
Las fotos aprobadas tienen un custom field con el valor
fanfoto_aprobada que lo establece el responsable de dicha tarea a cada imagen.