我有一个返回帖子的AJAX请求。这个post_content
有指向Twitter、YouTube、TED和其他平台的链接,这些平台在默认的vanilla WordPress安装中注册为oEmbed提供商。到目前为止,WordPress oEmbed处理程序没有注册它们,只显示普通链接,没有其他内容。
如何通过支持oEmbed的AJAX获取内容?
我有一个返回帖子的AJAX请求。这个post_content
有指向Twitter、YouTube、TED和其他平台的链接,这些平台在默认的vanilla WordPress安装中注册为oEmbed提供商。到目前为止,WordPress oEmbed处理程序没有注册它们,只显示普通链接,没有其他内容。
如何通过支持oEmbed的AJAX获取内容?
事实上,这很容易–当您知道缺少什么时:全球$wp_embed
对象,因此它知道要引用什么。原因很简单:oEmbed被缓存为post元数据,因此在不知道ID的情况下,标记无法在内容中获取和替换。
// grab a post from the database
/** @var \\WP_Embed $wp_embed */
global $wp_embed;
/** @var \\WP_Post $post; */
// Add the fetched posts ID and add it to the global object
$wp_embed->post_ID = $post->ID;
// Execute the [embed] shortcode
$wp_embed->run_shortcode( $post->post_content );
// Execute the oEmbed handlers for plain links on the own line
$wp_embed->autoembed( $post->post_content );
就是这样。更多in depth 有关oEmbed和缓存的信息可以在@birgire的相关答案中找到
我使用下面的代码通过单词标签获取帖子$search_songs = array( \'posts_per_page\' => -1, \'post_type\' => \'songs\', \'tax_query\' => array ( array ( \'taxonomy\' => \'post_tag\',