Return VIDEO thumbnail from posts
-
Hi guys,
I’d like to have a loop in the sidebar which searches my posts for youtube video’s and returns a thumbnail if the post does have a video embedded.
So I got this:
<?php global $wpdb; $sql="SELECT 'ID','post_title','post_content' FROM '{$wpdb->posts}' WHERE 'post_status'='publish' AND 'post_content' like '%https://www.youtube.com/v/%'"; $posts=$wpdb->get_results($sql); foreach($posts as $p) { if (preg_match("/\/watch\?v=(.*?)[&\"]/i",$p->post_content,$match) ) { $img = "https://i2.ytimg.com/vi/{$match[1]}/default.jpg"; echo $img; flush(); } } ?>
But it does not work! Can someone help me out?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Return VIDEO thumbnail from posts’ is closed to new replies.