Wordpress:显示post_format视频的视频

时间:2015-07-28 21:32:26

标签: php wordpress post-format

我的帖子有post_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;

1 个答案:

答案 0 :(得分:2)

最后我自己找到了一个解决方案:我创建了一个函数,为iframe帖子中的第一个视频返回$post_id

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];
}