[wp-hackers] Insert stuff into the excerpt based on a custom field, wipe out custom field

Matthew Gerring mgerring at emrl.com
Thu Sep 24 18:57:54 UTC 2009

Hello all,

This is the first time I've posted on this mailing list, hope this  
request isn't repetitive/annoying/whatever.

I'm trying to create a system that will parse YouTube URLs into a  
linked thumbnail with Shadowbox/lightbox/your favorite box integrated.  
To do that, I need a function that will check for a custom field,  
parse the URL, spit it back out formatted, then insert the formatted  
URL into post_excerpt and wipe out the custom field.

Here's what I have so far in my functions.php file of my theme:

function example($post_ID)

$yt = get_post_meta($post_ID, 'yt', TRUE);
if ($yt!="") {
	$qs = parse_url($yt);
	$lnk = '<a href="http://www.youtube.com/v/'.$v.'"><img src="http://img.youtube.com/vi/'.$v.'/0.jpg 
" alt="" /></a>';
	$n_post = array();
	$n_post['ID'] = $post_ID;
	$n_post['post_excerpt'] = 'wut';
	wp_update_post( $n_post );
	delete_post_meta($ins_id, 'yt');

add_action('save_post' , 'example');

I'm using save_post because according to the Codex, it runs right  
after a post is saved.

Now, this works, but it causes the request for post.php to timeout and  
I end up with a blank white screen. If I go look at my post, it's  
there, properly formatted, but I don't want freeze up saving posts for  
this. Is there a better way to do it?


More information about the wp-hackers mailing list