WordPress.org

Ready to get started?Download WordPress

Forums

Video Thumbnails
[resolved] Can't Find YouTube Thumbnails (25 posts)

  1. egurock
    Member
    Posted 2 years ago #

    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!

  2. Sutherland Boswell
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  3. mrmclen
    Member
    Posted 2 years ago #

    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!!

  4. Sutherland Boswell
    Member
    Plugin Author

    Posted 2 years ago #

    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!

  5. mrmclen
    Member
    Posted 2 years ago #

    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!

  6. ncpolicywatch
    Member
    Posted 2 years ago #

    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...

  7. dsdmdesign
    Member
    Posted 2 years ago #

    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?

  8. dsdmdesign
    Member
    Posted 2 years ago #

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

  9. Bad Feather
    Member
    Posted 2 years ago #

    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?

  10. Bad Feather
    Member
    Posted 2 years ago #

    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;
  11. Darrenmooney
    Member
    Posted 2 years ago #

    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 :)

  12. Bad Feather
    Member
    Posted 2 years ago #

    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);

  13. Darrenmooney
    Member
    Posted 2 years ago #

    @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.

  14. dsdmdesign
    Member
    Posted 2 years ago #

    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?

  15. flint_and_tinder
    Member
    Posted 2 years ago #

    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;
  16. Sutherland Boswell
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  17. flint_and_tinder
    Member
    Posted 2 years ago #

  18. finjoel@gmail.com
    Member
    Posted 2 years ago #

    Hi there,

    I have been trying to install the Video Thumbnail plugin on my WordPress blog mycrowdfundingstudy.com and I have not been able to successfully implement it.

    I am not sure if it an issue with the theme I selected or what, but I am not able to make the Vimeo videos posted show up as a thumbnail on the main page. I also uploaded the same video to WordPress, and there are no options in the Media dashboard to preview a thumbnail of this video.

    I went through the forum and the information on the main page, and have tried adding some of this code to the plugin, without success. I am not savvy enough to code my own PHP, so any help would be appreciated.

    Regards,

    Joel

  19. walser
    Member
    Posted 2 years ago #

    Hi
    I'm trying to get this work with embedded vimeo videos (iframe embed) and custom field (called 'embed'). I changed the "// Gets the post's content" part as described above and changed $video_key = 'video' to $video_key = 'embed'; However, so far without success. Any ideas what else I need to do in order to get this work?
    Thanks
    Ingo

  20. Chozen
    Member
    Posted 2 years ago #

    I tried the following code below for getting thumbnails from custom fields and it worked great with one exception. In WordPress 3.3 it doesn't create the thumbnail while the post is being published but instead after I have to click the search link in the Video Thumbnails box and then it creates the thumbnail. How do I make it create the thumbnail from a custom field while the post is being published?

    // Gets the post's content
    $video_key = 'video';
    $markup = get_post_meta($post_id, $video_key, true);
    $new_thumbnail = null;
  21. bazel
    Member
    Posted 2 years ago #

    Same here. This work with custom field but only if click Seach Again. Its not working when its published

  22. Sutherland Boswell
    Member
    Plugin Author

    Posted 2 years ago #

    @Chozen @bazel it sounds like maybe the custom fields aren't being saved until after the Video Thumbnail action. Try changing

    add_action('new_to_publish', 'save_video_thumbnail', 10, 1);
    add_action('draft_to_publish', 'save_video_thumbnail', 10, 1);
    add_action('pending_to_publish', 'save_video_thumbnail', 10, 1);
    add_action('future_to_publish', 'save_video_thumbnail', 10, 1);

    in the plugin file to

    add_action('new_to_publish', 'save_video_thumbnail', 20, 1);
    add_action('draft_to_publish', 'save_video_thumbnail', 20, 1);
    add_action('pending_to_publish', 'save_video_thumbnail', 20, 1);
    add_action('future_to_publish', 'save_video_thumbnail', 20, 1);

    and let me know if this fixes the problem for you. I'm going to try to include official custom field support in an upcoming version, and I'll include this change if it fixes your problem.

  23. Chozen
    Member
    Posted 2 years ago #

    Nope, still no luck but here's what I've discovered, when you save the post then publish it, the thumbnail gets created. But that's no different from searching for the post after the post has been published.

    It's still a extra step, and since my site is a multi author site, it going to be difficult trying to get everyone to remember to save before publishing.

  24. Chozen
    Member
    Posted 2 years ago #

    @Sutherland Boswell, you should consider making the custom field feature a native option for the next update of the plugin. That would be a very useful addition.

  25. Chozen
    Member
    Posted 2 years ago #

    Sorry I didn't see that you said you were gonna support custom fields in the next release.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic