Im trying to wrap video urls and embed code in a classed div so that I can style it. The vid code is being pulled from the custom meta value I've setup for the video post type. Nothing I've been able to find via the forum or google seems to quite answer my question.

Use case: The user either enters a youtube url into the video meta field, or they plunk in the entire embed code. Either way I need to wrap the output in some classed divs (fitvid).

Im new with WP and was hoping someone could explain: Why the urls Im passing to the_content in the code below, not being phrased by the [embed] shortcode? And what do I have to do to get it to?

From what I can tell, my options are either get [embed] to recognise the urls as video and do their magic -- or try to do the detection myself (which is a bit beyond my reach ATM :) ).

Here is what I have so far:

<?
$mykey_values = get_post_custom_values('_format_video_embed');
foreach ( $mykey_values as $key => $value ) {
if (!empty($value)) {
// I can get one or the other to work but not both
//$var = apply_filters('the_content', "[embed]" . $value . "[/embed]");
//this will only return the url - but why?
$var = apply_filters('the_content', $value );
}
echo "<div id='fitvid'>$var</div>";
} ?>
<?php the_content(); ?>

I wrote a very quick and simple mark-up that works -- I know WordPress has a built in oEmbed system, this doesn't follow it - at all. However, I'd be a fool not to share it if you can adapt a solution that works for me at least.

Sampled Code Notes: For this project I had to create a custom post type for videos so that my client could easily go in and add video posts with the Video ID from YouTube. These videos were of Houses their company had listed, and then professionally had videos shot. Their current workflow worked, and the rate of developing a video was about 5-6 weeks per, and maybe 13-15 videos per year.

When I had to start this project it was my understanding then that the oEmbed wasn't really needed for my uses, I may now in retrospect regret the decision on the argument of syntax, elegance, etc -- albeit, it's been rigid enough for this long without fail.

With that said, I also used a Custom Metabox Class to use get_post_meta for the ID of the video, I didn't ever build in Validation or Sanitizing of the input in the case that a video wasn't entered with the expectation of someone posting to a custom post type of videos that they would in fact not skip this very simple step. I'm a little over-confident at times, therefore you might want to add in some of that stuff per your needs

Getting Started: Create a `page-your-custom-post-type.php and put in the following:

It is important that 'post_type' => 'your-custom-post-type' is linked to your page-your-custom-post-type.php page, otherwise it won't know what to output. Additionally, you can add more parameters to the WP_Query array()WP_Query WordPress Codex Page.

Linking to your custom post type by default WordPress will feed this through single.php if it exists and fallback to index.php if single.php doesn't exist. However, If you create a single-your-custom-post-type.php WordPress will use that as your page-template for your custom post type.

thanks for this. A really interesting implementation and I'll spend some more time with this in the morning (1 am here in Scotland, happy Easter btw). Im not sure, for all the same reasons you mentioned, if I want to create and recreate an oEmbed wrapper. For one, the meta keys all work well for me, and secondly - I won't know exactly which service folks will use (youtube/vimeo) so would rather get wordpress to detect the url as it would normally (if possible). It is processing the embed shortcode, just not detecting the naked url as a video link. Anyone know how or when that happens?
–
orionrushApr 9 '12 at 0:02