Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I really need some help with this because I totally stumped.

I'd like to make a metabox with a name and a url input on my custom post type.

I want the result to show up in my content on my post.

I have a movie review site. So for example I want it to look like this:

Mission Impossible 5 (2012)

Ethan Hunt is at it again, but this time it personal. The evil meta box code is stopping him from building his site!

Youtube Link: youtube.com/blahblah

So if anyone can help that would really be great because this is just beyond my comprehension.

share|improve this question
    
there are a gazillion tutorials on this subject. not to mention there is a working example in the Codex: codex.wordpress.org/Function_Reference/add_meta_box –  helgatheviking Sep 16 '12 at 15:09
add comment

2 Answers 2

Imho, the fastest way would be by using the Meta Box Wrapper Class, which is a plugin by now. Download and activate it.

Next in your functions.php add the following:

$prefix = 'cheas_cool_metabox_';
global $meta_boxes;
$meta_boxes = array();

$meta_boxes[] = array(
    'id' => 'movie_reviews',
    'title' => 'Movie Review',
    //Change the next line if you want to display on another post type
    'pages' => array( 'post' ),
    'context' => 'side',
    'priority' => 'high',

    // List of meta fields
    'fields' => array(
        array(
            // Field name - Will be used as label
            'name' => 'Movie Title',
            // Field ID, i.e. the meta key
            'id' => $prefix . 'movie_title',
            'type'  => 'text',
        ),
        array(
            'name' => 'Review',
            'id' => $prefix . 'movie_review',
            'type'  => 'textarea',
        ),
        array(
            'name' => 'Link',
            'id' => $prefix . 'movie_link',
            'desc' => 'Youtube Link',
            'type'  => 'text',
        ),
    ),

);


function cheas_cool_metabox_register_meta_boxes()
{
    global $meta_boxes;

    if ( class_exists( 'RW_Meta_Box' ) )
    {
        foreach ( $meta_boxes as $meta_box )
        {
            new RW_Meta_Box( $meta_box );
        }
    }
}
add_action( 'admin_init', 'cheas_cool_metabox_register_meta_boxes' );

Now all you need to do is to call it on your post page:

Movie: <?php echo rwmb_meta( 'cheas_cool_metabox_movie_title' ); ?>
Review: <?php echo rwmb_meta( 'cheas_cool_metabox_movie_review' ); ?>
Watch Trailer for <a href="<?php echo rwmb_meta( 'cheas_cool_metabox_movie_link' ); ?>" target="_blank"><?php echo rwmb_meta( 'cheas_cool_metabox_movie_title' ); ?></a>

This should do it for you, but check out the demo folder in the main plugin directory to see more examples of different meta box types

share|improve this answer
    
I used to use WP Alchemy all the time, but Rilwis' plugin/class is probably even easier to use. –  helgatheviking Sep 16 '12 at 15:08
add comment

There are two parts to what you need to do:

  1. Create the meta field (Youtube URL).
  2. Output that custom meta field in your page template (probably single-movie.php).

For the first part, there is plenty of documentation available, just search 'create custom meta field/box' and follow along. Here's an example of how to do it. And for the second, you'll simply output the meta field where desired in the relevant template file.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.