Leave a Reply

1 comment

  1. The following will work inside the Output Buffer (ob_* functions). The global $post is just for testing, in your code it’s defined in the loop.

    add_shortcode( 'test-wp-embed', function( $atts, $content )
    {
        global $post, $wp_embed;
        ob_start();
        $mp3 = get_post_meta( $post->ID, 'wpshed_textfield', true );
        echo do_shortcode( $wp_embed->autoembed( $mp3 ) );
        $myvariable = ob_get_clean();
        return $myvariable;
    });
    

    But I’d suggest changing your code to use get_posts instead of WP_Query. In that case and without the output buffering, this works:

    add_shortcode( 'test-wp-oembed', function( $atts, $content )
    {
        global $post;
        $mp3 = apply_filters( 'the_content', get_post_meta($post->ID, 'wpshed_textfield', true ) );
        return $mp3;
    });