Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress:显示post_格式视频的视频_Php_Wordpress_Post Format - Fatal编程技术网

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