Jetpack embed not work with Custom fields

Hi, I use custom fields to add a youtube videos with this code in my template:

function video($post_id){
$video_embed = get_post_meta($post_id, 'url_video', true);
$video_insertar = wp_oembed_get( $video_embed ); // WP estandard
return '<div class="video-container"><p>'. $video_insertar.'</p></div>';
}

My problem is that I can’t use this method for the jetpack embeds (facebook, twitter, etc.) because not show anything.

My test page: http://ggsalas.staging.wpengine.com/pub/videos/

Best regards,

Gabriel

  • Patrick Cohen
    • Technical Docs Wrangler

    Hi again @ggsalas

    Whoops, nobody dropped in here to help out yet? Sorry about that.

    I’d just like to be sure I understand the issue before calling out for more help again.

    Please correct me if I am wrong, but are you are trying to embed videos from Facebook and Twitter by entering a URL in your custom field? Is that it?

  • Arnold
    • El Macho WP

    HI ggsalas,

    Are you absolutely sure your function is returning valid values? For example your call to:

    $video_insertar = wp_oembed_get( $video_embed	 );

    What does it actually return when you call it. If the function is return an empty string then the problem is in WordPress not interpreting the url.

    You can check it easily enough. After the above line in your function add

    print_r($video_insertar); exit.

    That will display the resulting whatever and stop immediately so you can see what it is without displaying other things over it, If it’s returning an empty string then you have an url that WordPress doesn’t recognize for oembed.