<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
		>
	<channel>
		<title>Wordpress and Webdesign Forum go41 &#187; Topic: get the oembed code of a video in a WP 2.9 post from postmeta</title>
		<link>http://forum.go41.de/topic/get-the-oembed-code-of-a-video-in-a-wp-29-post-from-postmeta</link>
		<description>How To, tips, php and css code for your WordPress site</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 23:03:25 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.1</generator>
				<atom:link href="http://forum.go41.de/rss/topic/get-the-oembed-code-of-a-video-in-a-wp-29-post-from-postmeta" rel="self" type="application/rss+xml" />

		<item>
			<title>masteradmin on "get the oembed code of a video in a WP 2.9 post from postmeta"</title>
			<link>http://forum.go41.de/topic/get-the-oembed-code-of-a-video-in-a-wp-29-post-from-postmeta#post-101</link>
			<pubDate>Mon, 21 Dec 2009 14:19:51 +0000</pubDate>
			<dc:creator>masteradmin</dc:creator>
			<guid isPermaLink="false">101@http://forum.go41.de/</guid>
			<description><![CDATA[<p>The latest WordPress 2.9 got a new function to automatically embed all plain text URLs with the help of oembed. On a blog displaying resized images together with the_excerpt it is nice to show also the embeded video clips if there is no image.<br />
So how to get the code to embed a video from the database?<br />
In WordPress 2.9, if you insert a plain URL link to a video from an oembed enabled site, WordPress will try to put the whole code around this URL to embed this video in a player.<br />
This code will not show up in edit posts, but is written to postmeta table. The meta_key is looking like '_oembed_74dd854eb13572c16.....' and it's meta_value is the actually html code to get parsed.</p>
<p>Working inside the loop, we are going to get the unique meta_key of a post starting with oembed. If in a post is this meta_key we assign this to a variable (here: $oembkey)<br />
Next we get the value of this key, which is actually the full html embed code (here: $embedhtml)</p>
<p>Finally we can echo $embedhtml to display only the video without the_content or the_excerpt.</p>
<p>The code to get only the embeded video:</p>
<pre><code>&#60;?php
  $custom_field_keys = get_post_custom_keys();
  foreach ( $custom_field_keys as $key =&#62; $value ) {
    $valuet = trim(substr($value, 1, 4));
	if ( &#39;oemb&#39; == $valuet ) { // look if a oembed key exists
    $oembkey = $value; //now set the the key we found as oembkey
	$oembvalue = get_post_custom_values($oembkey); //get the value of oembkey as oembvalue
	if (isset($oembvalue[0])) {
		$embedhtml = ($oembvalue[0]);
	  }
	}
  }
?&#62;</code></pre>
<p>and now echo it:</p>
<pre><code>&#60;?php echo $embedhtml; ?&#62;</code></pre>
<p>In another topic I will explain how to resize this player here:<br />
<a href="http://forum.go41.de/topic/change-width-and-height-in-oembed-code-on-the-fly-wp-29">Change width and height in oembed code on the fly WP 2.9</a>
</p>]]></description>
					</item>

	</channel>
</rss>

