Php Wordpress:显示post_格式视频的视频
我有一篇带有Php Wordpress:显示post_格式视频的视频,php,wordpress,post-format,Php,Wordpress,Post Format,我有一篇带有post\u format=video的帖子,其中的内容是视频和文本(在默认编辑器中)。我需要分别显示视频和文本。你怎么能做到 目前,我有以下代码: global $post; $tmp_post = $post; $args = array( 'posts_per_page' => 1, 'post_type' => 'post', 'post_status' => 'publish', 'order' => 'D
post\u format=video
的帖子,其中的内容是视频和文本(在默认编辑器中)。我需要分别显示视频和文本。你怎么能做到
目前,我有以下代码:
global $post;
$tmp_post = $post;
$args = array(
'posts_per_page' => 1,
'post_type' => 'post',
'post_status' => 'publish',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array( 'post-format-video' ) // post format
)
)
);
$video_posts = get_posts( $args );
foreach ($video_posts as $post ) :
setup_postdata( $post );
echo get_the_title($post->ID);
// ------> Here what code for get the video?
// html
// ...
// ...
// ------> Here what code for get the text (if possible)?
endforeach;
$post = $tmp_post;
最后,我自己找到了一个解决方案:我制作了一个函数,返回id为
$post\u id
的文章中第一个视频的iframe
:
function get_first_video_embed($post_id) {
$content = apply_filters('the_content', get_post_field('post_content', $post_id));
$iframes = get_media_embedded_in_content( $content, 'iframe' );
return $video_post_iframe = $iframes[0];
}