2

I'm getting all videos using the function below and it's working fine. Now I want to get the videos Poster Image (Thumbnail Image) from that video. How can I get the video Image as thumbnail? I've also tried to get thumbnail by this function but It's not working

    $page_id = 659; 
    $page_data = get_page( $page_id ); 

    if (has_post_thumbnail( $page_data->ID ) ){ ?>
    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $page_data->ID ), 'single-post-thumbnail' ); ?>
    <img src="<?php echo $image[0]; ?>" width="200" height="212" />
    <?php }?>

I'm getting all videos by this function

    $args = array
            (
                'post_type' => 'attachment',
                'post_mime_type' => 'video',
                'order' => 'DESC',
                'orderby' => 'post_date',
                'posts_per_page'  => -1
            );
            $videoFiles = get_posts($args);
             foreach ($videoFiles as $file) {
    }

My post object:

WP_Post Object
(
    [ID] => 670
    [post_author] => 1
    [post_date] => 2013-06-26 10:55:51
    [post_date_gmt] => 2013-06-26 10:55:51
    [post_content] => Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,
    [post_title] => Strike Back
    [post_excerpt] => Composer
    [post_status] => inherit
    [comment_status] => open
    [ping_status] => open
    [post_password] => 
    [post_name] => columbia4x3
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2013-06-26 10:55:51
    [post_modified_gmt] => 2013-06-26 10:55:51
    [post_content_filtered] => 
    [post_parent] => 0
    [guid] => http://host.com/wp-content/uploads/2013/06/Columbia4x3.mov
    [menu_order] => 0
    [post_type] => attachment
    [post_mime_type] => video/quicktime
    [comment_count] => 0
    [filter] => raw
)
4
  • Ok, but where do you want to get the poster file from? Is it an image file attached to the same post? Any custom field where you put this info? Or is it the very featured image that must be used as poster?
    – brasofilo
    Commented Jun 26, 2013 at 10:22
  • Dear Brasofilo, It's an image file which is attached to the same post. I've done it with custom query and it's working but if do you have any other option please let me know. I use $sql = "select * from ".$wpdb->prefix."posts where ID=(select meta_value from ".$wpdb->prefix."postmeta where post_id=".$file->ID." and meta_key LIKE '%jwplayermodule_thumbnail%')";
    – Tariq
    Commented Jun 26, 2013 at 10:32
  • 1
    You don't need a direct DB query. Inside your video foreach use the same thumbnail logic using $file->post_parent as the page ID.
    – brasofilo
    Commented Jun 26, 2013 at 10:56
  • Dear brasofilo, post_parent is returning 0. I've posted my code above please see.
    – Tariq
    Commented Jun 26, 2013 at 12:47

1 Answer 1

1

Your video does not appear to be "attached" to the page, hence the 0 as post_parent. And your query arguments do not restrict the results to any particular page.

You won't be able to use the normal thumbnail functions. You will have to use something like wp_get_attachment_image to get the thumbnail, if you have a thumbnail at all for the video. I just ran a test and did not have a thumbnail generated for the video.

If you are not already generating thumbnails, that is your first project. If you are generating them, explain how.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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