Primus202
Primus202

Reputation: 646

Wordpress (Pods) oEmbed Items

I'm using the fantastic Pods plugin to extend Wordpress's basic content types with a few custom ones. I've build an advanced custom type which means I don't get the automatic oEmbed support built into the native page/post types. I've structured it so my custom content type has a pod page using a PHP page template and I have the oEmbed option enabled for my WYISWYG fields that can embed videos.

I found this post which seems to indicate that a basic apply_filter function should automatically handle any embeds but I can't seem to get it to work. I'm a bit new to filters. The code I tried is below:

<?php
// Fetch body field content from $pods object
$mycontent = $pods->field('field_body');
$output = apply_filters('oembed_dataparse', $mycontent);
echo $output;
?>

I tried a variety of different filters such as the_content and others but none seemed to work. I believe it may be a scoping/conflict issue with Pod pages since even writing out entire iFrame embed code into the template won't work but only displays an empty iFrame. The global oembed function does the same, i.e.

$videourl = 'http://www.youtube.com/watch?v=dQw4w9WgXcQ';
$htmlcode = wp_oembed_get($videourl);
echo $htmlcode;

In the context of the page template will output:

<iframe width="500" height="375" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/dQw4w9WgXcQ?feature=oembed">
    <html>
        <head>
        </head>
        <body>
        </body>
    </html>
</iframe>

Upvotes: 1

Views: 2439

Answers (2)

Scott Kingsley Clark
Scott Kingsley Clark

Reputation: 987

field() gets the value of the field, display() gets the output of the field (ran through any related filters / functions the field is configured to run through).

$mycontent = $pods->field('field_body');

should be

$mycontent = $pods->display('field_body');

For more information, see http://pods.io/docs/field/ vs http://pods.io/docs/display/

Upvotes: 1

KalenGi
KalenGi

Reputation: 2077

Calling apply_filters('oembed_dataparse', $mycontent) is incorrect since this meant to add functionality for processing other data types (photo, video etc) not catered for by default. What you want to do is mimic how WordPress does the embedding. I haven't tested the code below, but it seems to me the way to go about triggering the embed functionality:

global $wp_embed;

$mycontent = $pods->field('field_body');

$output = $wp_embed->autoembed($mycontent);

echo $output;

Upvotes: 0

Related Questions