New answers tagged oembed
You need to set the global $post object to your post. This is done by the loop functions in your theme which is why it works there. WP's oEmbed replaces the URLs during the the_content filter. But it replaces the URLs through two means. The first is a simple regex find and replace for certain URLs such as Google Video or linking directly to a file with a ...
"autoembedding", at least last I checked, operates due to a filter on the_content. Your code does not apply that filter. $thePost = get_post(42, ARRAY_A); $theContent = $thePost['post_content']; echo apply_filters('the_content',$theContent); Assuming that the WordPress Core is loading correctly, that should get the embeds working.
Top 50 recent answers are included