go41

get the oembed code of a video in a WP 2.9 post from postmeta

von Joern am 21. Dez. 2009 | Keine Kommentare

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.

So how to get the code to embed a video from the database?

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.

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

Next we get the value of this key, which is actually the full html embed code (here: $embedhtml)
Finally we can echo $embedhtml to display only the video without the_content or the_excerpt.
The code to get only the embeded video:
Code:

<?php
  $custom_field_keys = get_post_custom_keys();
  foreach ( $custom_field_keys as $key => $value ) {
    $valuet = trim(substr($value, 1, 4));
   if ( 'oemb' == $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]);
     }
   }
  }
?>

and now echo it:
<?php echo $embedhtml; ?>
In another topic I will explain how to resize this player here:

Change width and height in oembed code on the fly WP 2.9
____________________
you find me on Google+, Twitter and Facebook

(von: master)

Hier noch 2 weitere Ergebnisse dieses Threads:

Display SEO SearchTerms Tagging 2 differently on templates

6. Jul. 2012 (von: Joern)

Using the plugin 'SEO SearchTerms Tagging 2' I was looking for a way to display the related search terms differently on certain templates.In the dashboard settings of SearchTerms Tagging 2 you can set to display with link to post content…

Re: Display SEO SearchTerms Tagging 2 differently on templates :: Reply by testonly

25. Aug. 2012 (von: testonly)

I have been used this SEO SearchTerms Tagging 2 plugin in my website. Weiterlesen →

wichtig:

  • https://www google com/

Autor:

Du findest mich auch auf Twitter und Facebook!

Schreibe einen Kommentar

Pflichtfelder sind mit * markiert.


Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.

weitere forum Beiträge: