I'm trying to show all the posts on a page with an audio player in it and for that I'm looping through posts in the following manner:
<?php
$posts = get_posts();
$ID;
foreach( $posts as $item)
{
global $post;
$post_id = $item->ID;
$file_id = get_post_meta($post_id, 'sound_s', true);
$file_url = wp_get_attachment_url( $file_id );
$attr = array(
'src' => $file_url,
'loop' => '',
'autoplay' => '',
'preload' => 'none'
);
echo wp_audio_shortcode( $attr );
$ID = $file_id;
var_dump($file_id);
}
?>
But trying to echo or var_dump $file_id is returning in null due to which my audio player can not be shown. And yeah there's no mistake in meta key and $post_id is also returning currect value. So please tell me why is this happening?