显示POST_FORMAT视频

时间:2015-07-28 作者:Fred K

I\'ve a post with post_format = video, in which the content are a video and a text (in the default editor). I need to display the video and the text separately. How can do it?

For now, I\'ve this code:

  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 个回复
SO网友:Fred K

我做了一个函数,返回iframe 对于id为的帖子中的第一个视频$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];
}

结束

相关推荐

自定义小工具在放置在其自己的PHP文件中时创建PHP异常

我创建了一个自定义插件和一个小部件。目前,该代码包含在插件的基本php文件中,并且工作正常。我想将小部件和所有未来的小部件移动到一个小部件中。php文件,并将其包含到主插件文件中。当我这样做时,我得到以下php错误。PHP致命错误:调用/var/www/wordpresstest/wp includes/capabilities中未定义的函数wp\\u get\\u current\\u user()。php在线1387这是小部件的代码。当我将此代码放在主插件php文件中时,它可以完美地工作,但当我使用r