Support » Plugin: CMB2 » oEmbed question

  • Resolved jmaurer

    (@360zen)


    So, I’m new to CMB2 and trying to allow the client to embed videos with a url using the oEmbed custom field. Everything seems to be working properly, but I’m not sure how to echo the field properly to get it to spit out the embed code instead of the url value.

    This code:

    $video = get_post_meta( get_the_ID(), '_cmb2_video_embed', true );
    echo $video;

    results in the text “http://youtu.be/xxxxxxxx”.

    EDIT:
    This code (from this thread):

    global $wp_embed;
    echo $wp_embed->run_shortcode('[­embed]'.$video.'[/embed]');

    results in the text “[embed]http://youtu.be/xxxxxxxx[/embed]“.

    Any help is much appreciated. Thanks in advance!
    https://wordpress.org/plugins/cmb2/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jmaurer

    (@360zen)

    I believe I have answered my own question. It appears that the following is working as expected:

    $video = get_post_meta( get_the_ID(), '_cmb2_video_embed', true );
    echo wp_oembed_get( $video );

    If there is a better way to do it, I’d love to know it. Otherwise, I’ll consider this resolved.

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    You could always add the the_content filter to the $video result, but that may not be much different than the solution you have now, and it’d make you have to contend with other things that add filters to the_content.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘oEmbed question’ is closed to new replies.