Youtube URL和其他通过名为oEmbed. 您需要使用wp_oembed_get() 获取嵌入内容以使其工作。
在您的情况下,您直接插入内容,所以您可能不想只打电话wp_oembed_get() 今天到此为止。那行不通。最好运行WordPress内置的功能来支持帖子内容。
apply_filters( \'the_content\', $content );
 当您输出
the_content() 并包括诸如短代码扩展和oembed发现之类的内容。但是,只有当您的内容格式正确时,它才会起作用。您说,“WP Codex上的嵌入页面表示只需将“视频URL放入内容区域”,这是正确的,有一点需要澄清:
确保URL位于其自己的行上,而不是超链接。
插入内容如下所示:
$new_post = array(
    \'post_title\'   => $title,
    \'post_content\' => \'test
    https://www.youtube.com/watch?v=4g3e8XwVIYc
    https://youtu.be/LPpW_8c5jE4\',
    \'post_status\'  => \'publish\',
    \'post_author\'  => $author,
    \'post_type\'    => \'post\',
);
wp_insert_post( $new_post, true );
 请注意帖子内容的新行。这将在模板中输出这些youtube URL时,将其转换为适当的嵌入。