troubleshooting Question

Creating a Custom Metabox in Wordpress

Avatar of Adam
AdamFlag for Canada asked on
WordPressPHPWeb Development
10 Comments1 Solution651 ViewsLast Modified:
I'm trying to create a custom metabox in Wordpress for a custom post type. I found a nice little tutorial that actually explains it rather well:

http://wptheming.com/2010/08/custom-metabox-for-post-type/

The only part of the tutorial that I don't understand is where he adds the text input field.

// The Event Location Metabox
 
function wpt_events_location() {
    global $post;
 
    // Noncename needed to verify where the data originated
    echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' .
    wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
 
    // Get the location data if its already been entered
    $location = get_post_meta($post->ID, '_location', true);
 
    // Echo out the field
    echo '<input type="text" name="_location" value="' . $location  . '" class="widefat" />';
 
}

I don't know where "wp_create_nonce( plugin_basename(__FILE__) )" comes from or what exactly it does. Having said that, I'm actually looking to have checkboxes in my metabox rather then an input field. But because I don't completely understand the code behind adding an input field, I'm not entirely sure what I would need to do for checkboxes. Can someone help me out?

A second part to that question—is it possible to configure it so that it is mandatory for an author to select one of the checkboxes in my custom metabox before they can publish the post?
ASKER CERTIFIED SOLUTION
Adam

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros