0

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
    How do you add the video into the editor: oEmbed urls, shortcodes or ...? – birgire Jul 29 '15 at 0:37
  • I just paste the video link in the editor, then it automatically show it – Fred K Jul 29 '15 at 7:03
1

I made a function that return the iframe for the first video inside the post with 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];
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.