0

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

1
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

1
  • I used to use WP Alchemy all the time, but Rilwis' plugin/class is probably even easier to use. Sep 16 '12 at 15:08
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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