This works just fine in any other post:
$vid_att = get_attached_media('video',$post_id); // Check if a video is attached
// print_r($vid_att);
if ($vid_att) {
$vid_att_url = wp_get_attachment_url($vid_att->ID);
echo $vid_att_url;
}
HOWEVER
if I use this within my functions.php file it will return the full array (print_r($vid_att);) but will not return the ID when requested!
If I insert the attachment ID manually it works:
$vid_att_url = wp_get_attachment_url('138');
What can it be? I've tried converting ID to Integer and other stuff but cannot get it to work. Also ne errors given.
The array it returns looks like this:
Array ( [138] => WP_Post Object ( [ID] => 138 [post_author] => 1 [post_date] => 2018-08-14 16:21:42 [post_date_gmt] => 2018-08-14 16:21:42 [post_content] => [post_title] => SampleVideo_1280x720_1mb [post_excerpt] => [post_status] => inherit [comment_status] => open [ping_status] => closed [post_password] => [post_name] => samplevideo_1280x720_1mb [to_ping] => [pinged] => [post_modified] => 2018-08-14 16:21:42 [post_modified_gmt] => 2018-08-14 16:21:42 [post_content_filtered] => [post_parent] => 113 [guid] => http://flockstock/wp-content/uploads/edd/2018/08/SampleVideo_1280x720_1mb.mp4 [menu_order] => 0 [post_type] => attachment [post_mime_type] => video/mp4 [comment_count] => 0 [filter] => raw ) )