Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter eric.downing

    (@ericdowning)

    Sorry I didn’t see another person asked the same question

    get_post_meta($attachment_id, “_kgflashmediaplayer-poster”, true);

    Thread Starter eric.downing

    (@ericdowning)

    It appears that not all videos have a poster image stored in this location, but the poster image is shown when the video is called with the shortcode. I checked the database and some metas are empty.

    Plugin Author Kyle Gilman

    (@kylegilman)

    Can you see any pattern to the videos that are missing the meta field?

    If I remember correctly I introduced that feature in version 3.0, so if you were using an older version and created the poster images at that time, it wouldn’t have the meta field.

    Thread Starter eric.downing

    (@ericdowning)

    Videos from the older version may have been the issue.

    I used the following code to get the image. My videos are in a custom post so my post_type is “videos”

    global $wpdb;
    $posts = $wpdb->get_results("SELECT ID, post_title, post_content FROM $wpdb->posts WHERE post_type = 'videos' AND post_status = 'publish' ORDER BY ID DESC", ARRAY_A);
    foreach($posts as $post) {
    
    $pat = '/\"([^\"]*?)\"/'; // text between quotes excluding quotes
    preg_match($pat, $post[post_content], $matches);
    
    ?>
    <img src="<?php echo $matches[1];?>"/>
    <?php
    }
    ?>
    Plugin Author Kyle Gilman

    (@kylegilman)

    Ah, that’s a good solution. For anyone else who wants to try this, it assumes that the poster attribute is always in the same position among all text in the post between quotes. Since Eric has control over that and it seems like all of the “video” posts only have the shortcode in the post_content (and only have one shortcode) it will work well.

    In the next release I’ll include an option to set the video thumbnail as the featured image for the post, which should make things even simpler.

    Thread Starter eric.downing

    (@ericdowning)

    If your poster is in another position just change $matches[1] to whatever spot it’s in. Lets say the poster in the third spot then you would use.

    <img src="<?php echo $matches[3];?>"/>

    Each “” in the shortcode is counted as 1 spot.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Query Poster Image’ is closed to new replies.