Estoy tratando de obtener algunos metadatos de un archivo mp3 en WordPress. Concretamente la variable longitud. Aquí hay un poco de mi código. No se muestra aquí, pero he incluido el archivo wp-admin/includes/media.php. Cuando miro mi página http://beta.openskyministry.org/podcasts/ solo veo etiquetas vacías para <itunes:length></itunes:length>
Avíseme si necesita algo más para ayudar a responder mi pregunta.
$aud_meta = wp_read_audio_metadata($aud_url); ?> <item> <title><?php the_title(); ?></title> <itunes:author><?php echo htmlspecialchars((get_bloginfo('name'))); ?></itunes:author> <itunes:summary><?php echo htmlspecialchars(strip_tags(get_the_excerpt())); ?></itunes:summary> <itunes:length><?php echo $aud_meta['length_formatted']; ?></itunes:length>WordPress ya almacena metadatos de medios, por lo que no es necesario revisarlos. La solución es tan simple como:
add_action( 'wp_head', function(){ global $post; if ( is_single($post) ) { $args = array( 'post_type' => 'attachment', 'numberposts' => 1, 'post_parent' => $post->ID, 'post_mime_type' => 'audio' ); $attachments = get_posts( $args ); if($attachments){ $meta = wp_get_attachment_metadata( $attachments[0]->ID ); echo "<itunes:length>{$meta['length_formatted']}</itunes:length>"; } } }); Para los registros, wp_read_audio_metadata() espera la ruta del archivo, no la URL. Si es necesario, debe ser:
$path = get_attached_file( $attachment->ID ); $meta = wp_read_audio_metadata($path); echo "<itunes:length>{$meta['length_formatted']}</itunes:length>";Relacionado : ¿Guardar la información de la cámara como metadatos al cargar la imagen?