WordPress.org

Support

Support » Plugins and Hacks » Video Thumbnails » [Resolved] [Plugin: Video Thumbnails] Can't Find YouTube Thumbnails

[Resolved] [Plugin: Video Thumbnails] Can't Find YouTube Thumbnails

  • I uploaded a whole bunch of videos to youtube and they all have thumbnails created. But when I run the Video Thumbnail plugin, it doesn’t find any of them. I’m using a theme that stores the youtube video in a custom field, could that be the problem? If so, does anyone have a solution?

    thanks!

Viewing 15 replies - 1 through 15 (of 24 total)
  • Plugin Author Sutherland Boswell

    @sutherlandboswell

    Yep, the plugin only searches the main content of the post. To fix this, replace these lines:

    // Gets the post's content
    $post_array = get_post($post_id);
    $markup = $post_array->post_content;
    $markup = apply_filters('the_content',$markup);
    $new_thumbnail = null;

    with:

    // Gets the post's content
    $video_key = 'video';
    $markup = get_post_meta($post_id, $video_key, true);
    $new_thumbnail = null;

    You’ll have to change the value of $video_key = ‘video’ to the name of your custom field, but this should fix it as long as the field contains a full YouTube url.

    Hi I have been struggling with this for hours. I found two “names” for my custom field:

    In the source code it is name=”_tern_wp_youtube_video”
    on the form it is Youtube ID:

    I put the following code below and no thumbnails were found.

    // Gets the post’s content
    //my change
    $video_key = ‘_tern_wp_youtube_video’;
    $markup = get_post_meta($post_id, $video_key, true);
    $new_thumbnail = null;

    I added some code from another of your posts to clear the database and then removed it again when it did not work.

    delete_post_meta($post_id, ‘_video_thumbnail’);

    At one point I had your plugin installed and re-wrote all of my posts to have the URLs readable by your plugin but then I found a great plugin that will pull my Youtube Videos and post them for me using just the ID and puts the ID in a custom field.

    I even at one point tried to get some code to fix the short URL ID but I am over my head. I am good with HTML and CSS… PHP I can only ocasionally add some text to something that is echo’ed. I don’t know the syntax.

    Any help would be appreciated!!

    Plugin Author Sutherland Boswell

    @sutherlandboswell

    mrmclen,

    I think you’re on the right track, but if the plugin only stores the YouTube ID in the custom field, it doesn’t realize it’s a YouTube ID. It should be easy to fix this though by changing the line that sets $markup to a value that includes the rest of the URL. Just replace this one line in your current changes:

    $markup = 'http://youtube.com/watch?v=' . get_post_meta($post_id, $video_key, true);

    Let me know if it works!

    I have never been happier to receive an email! YES it worked!!! I have one red x saying it can’t find the thumbnail, but when I go to the posts it is there… I can now move on to the things that were not working without thumbnails. I almost went back to hand coding each video so this is awesome!! Thank you so much!

    Code is poetry… in the right hands!

    This is pretty awesome. Throwing a kink in there tho, but every once in a while, I’d like to be able to manually put in video links and have video thumbnails generate my thumbnails. But after this change for the automatic video posts, it’s not generating thumbnails for the manually inputed videos…

    I successfully implemented this on one site, and it’s still working, however when I used the same files to make this happen again on a new site, it’s now no longer working. This is still what I have:

    $video_key = '_tern_wp_youtube_video';
    $markup = 'http://youtube.com/watch?v=' . get_post_meta($post_id, $video_key, true);
    $new_thumbnail = null;

    is something wrong here?

    Nevermind got it working! I think it was an issue with old vs. new version of the plugin.

    I’m trying to get this to work as a conditional, ie. if the custom field isn’t empty, use the custom field, otherwise scan the content as is the default behavior in the plugin. Here’s what I’ve got so far:

    $videourl = get_post_meta($post_id, 'videourl', true);
    		if ( !empty( $videourl ) ) {
    			$markup = $videourl;
    		} else {
    			$markup = $post_array->post_content;
    			$markup = apply_filters('the_content',$markup);
    		}

    It’s still working for the custom field, but I can’t get it to pull thumbnails from the post content. Any thoughts?

    Got it working, if anyone else is trying to do the same thing. Fixed code below. Works for both custom field and post content:

    // gets custom field data
    $videourl = get_post_meta($post_id, 'videourl', true);
    if($videourl) {
    	$markup = $videourl;
    } else {
    	// Gets the post's content
    	$post_array = get_post($post_id);
    	$markup = $post_array->post_content;
    	$markup = apply_filters('the_content',$markup);
    }
    $new_thumbnail = null;

    I have been trying to get this to work with the plugin More Field (http://wordpress.org/extend/plugins/more-fields/).

    I use this code to display a custom more field.
    <?php echo(get_post_meta($post->ID, 'embed-code', true)); ?>

    From reading above I thought the following would work, but it doesn’t.

    $markup = get_post_meta($post->ID, 'embed-code', true);
    $new_thumbnail = null;

    Does anyone know what I’m doing wrong here?

    Thanks 🙂

    Hi Darren,

    Try changing this line:
    $markup = get_post_meta($post->ID, 'embed-code', true);

    To this:
    $markup = get_post_meta($post_id, 'embed-code', true);

    @brad2dabone

    I actually just got it working with the following:

    $video_key = 'embed-code';
    $markup = get_post_meta($post_id, $video_key, true);
    $new_thumbnail = null;

    Thanks for the reply.

    Is there a way to get it to work with ”_tern_wp_youtube_video’ like above but also automatically pull in thumbnails from new videos without having to manually click “scan posts” every time a new video is pulled in?

    flint_and_tinder

    @flint_and_tinder

    Does anyone know of a way I can search 1 custom field for a video ID and if no value is present check another. Using the code provided by Brad above I’ve got this far but youtube thumbnails still don’t work. I’m happy to pay someone for their expertise if this is a tricky thing to do.

    // gets custom field data
    $vimeoid = get_post_meta($post_id, 'vimeo_id', true);
    if($vimeoid) {
    	$markup = 'http://vimeo.com/'.get_post_meta($post_id, $vimeoid, true);
    } else {
    $youtubeid = get_post_meta($post_id, 'youtube_id', true);
    if($youtubeid) {
    	$markup = 'http://youtu.be/'.get_post_meta($post_id, $youtubeid, true);
    }
    }
    $new_thumbnail = null;
    Plugin Author Sutherland Boswell

    @sutherlandboswell

    I think you’re pretty close, try changing 'http://youtu.be/' to 'http://www.youtube.com/watch?v='

    I don’t think it currently checks for youtu.be links, but it’s something I should add.

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘[Resolved] [Plugin: Video Thumbnails] Can't Find YouTube Thumbnails’ is closed to new replies.
Skip to toolbar