I have this code:

<?php if ( has_post_format ('video') ) { ?>
    <div class="video-head">
        $video = get_post_meta( $post->ID, '_format_video_embed', true );
        if ( wp_oembed_get( $video) ) {
            echo wp_oembed_get($video);
        } else {
            echo $video;
        } ?>
<?php } ?>

And it should output, on the posts-list, say, homepage, the iframe of the video embedded in my post, like this:

enter image description here

For some reason, it doesn't.

The get_post_meta( $post->ID, '_format_video_embed', true ); fails and returns nothing.

The biggest issue is that WordPress sees the video as part of the content itself, rather than it having the video on a "higher up level" as "image" is for the "Image Post Type", it's left as nothing more than content, so, of course my query wouldn't pick it up.

What am I to do here?

  • What happens if you replace $post->ID with get_the_ID(). Note that wp_oembed_get() doesn't cache, last time I checked. Not sure if 4.9 changed that? – birgire Jan 5 '18 at 21:50
  • @birgire Still nothing. – Jonathan Guerin Jan 5 '18 at 21:57
  • Then try to replace it with the actual post ID to test, e.g. 1234. – birgire Jan 6 '18 at 2:15
  • What's the content of the _format_video_embed meta field? get_post_meta() will only return nothing if it's empty. Where did you save the video? – swissspidy Jan 22 '18 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.