I am trying to create a 'latest video' section. Basically, what I'm trying to do is get the custom field value (video url) from the last post in the 'video' post format. Then, I'm trying to insert that url into the YouTube embed code and echoing the entire embed code with the url included. Below is a code that I managed to put together. I'm sure there are some things wrong with it and was wondering if someone could help me make sense of this.
<?php $args = array( 'numberposts' => '1', 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => 'post-format-video' ) ) ); $latest_video = wp_get_recent_posts($args); // Get latest video in 'video' post format $latest_video_id = $latest_video['0']['ID']; // Get latest video ID $video_url = htmlspecialchars(get_post_meta(get_the_ID($latest_video_id), 'dt_video', true)); echo '<iframe width="180" height="101" src="'.$video_url.'?rel=0" frameborder="0" allowfullscreen></iframe>'; ?>
Edit: $video_url is returning an empty string.