Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

How to save custom meta box data in wordpress?

I have created a custom meta box with some fields in it. Now, i want to save that data in the database. Please help me the code is given below:-

//add meta box for the offer post function offers_add_meta_boxes(){ add_meta_box( 'offer_details', 'Offer Details', 'coupon_hawker_offer', 'offers', 'normal', 'high' ); } add_action( 'add_meta_boxes', 'offers_add_meta_boxes' );

function coupon_hawker_offer(){

wp_nonce_field( plugin_basename(_FILE_), 'offer-meta-box-nonce-feild');

//offer type goes here
$html = '<div class="meta_container">';
    //label goes here for offer type
    $html .= '<label for="offer_type" class="offer_label" id="offer_type">';
        $html .= "Offer Type";
    $html .= '</label>';
    //Selection box goes here
    $html .= '<select name="offer_types" class="input_types">';
        //first option
        $html .= '<option value="Coupon">';
            $html .= 'Coupon';
        $html .= '</option>';
        //second option
        $html .= '<option value="Deal">';
            $html .= 'Deal';
        $html .= '</option>';
    $html .= '</select>';
$html .= '</div>';

//Offer availabilty goes here
$html .= '<div class="meta_container">';
    //label goes here for availabilty
    $html .= '<label for="avail_as" class="offer_label">';
        $html .= "Availablity";
    $html .= '</label>';
    // selection for availablity type
    $html .= '<select name="availabilty" class="input_types">';
        //first option goes here
        $html .= '<option value="Offline">';
            $html .= 'Offline';
        $html .= '</option>';
        //second option goes here
        $html .= '<option value="Online">';
            $html .= 'Online';
        $html .= '</option>';
        //third option goes here
        $html .= '<option value="Both">';
            $html .= 'Both';
        $html .= '</option>';

    $html .= '</select>';
$html .= '</div>';

//Offer details goes here
$html .= '<div class="meta_container">';
    //label goes here
    $html .= '<label for="offer_details" class="offer_label" id="offer_details_label">';
        $html .= "Offer Details";
    $html .= '</label>';
    //text area for ofer details goes here
    $html .= '<textarea id="offer_details" name="offer_details" class="input_types">';
    $html .= '</textarea>';
$html .='</div>';

//Coupon code goes here
$html .= '<div class="meta_container">';
    //label goes here
    $html .= '<label for="Coupon_code" class="offer_label">';
        $html .= "Coupon Code";
    $html .= '</label>';
    //text box for coupon code
    $html .= '<input type="text" name="coupon_code" value=" " class="input_types">';
$html .= '</div>';

//Affilate link goes here
$html .= '<div class="meta_container">';
    //label goes here
    $html .= '<label for="Coupon_code" class="offer_label">';
        $html .= "Affilate link";
    $html .= '</label>';
    //input box for affilate link goes here
    $html .= '<input type="text" name="affilate_link" value=" " class="input_types">';
$html .= '</div>';

//Featured section goes here
$html .= '<div class="meta_container">';
    //label goes here
    $html .= '<label for="Featured" class="offer_label">';
        $html .= "Featured";
    $html .= '</label>';
    //checkbox for featured offers goes here
    $html .= '<input name="featured_offers" type="checkbox" id="featured" title="featured">';
$html .= '</div>';

//Activation date section goes here
$html .= '<div class="meta_container">';
    //label goes here
    $html .= '<label for="activation_date" class="offer_label">';
        $html .= "Activation Date";
    $html .= '</label>';
    //input for date goes here
    $html .= '<input type="date" name="activation_date" id="activation_date" value="" class="input_types" />';
$html .= '</div>';

//Expiry date goes here
$html .= '<div class="meta_container">';
    //label goes here
    $html .= '<label for="expiry_date" class="offer_label">';
        $html .= "Expiry Date";
    $html .= '</label>';
    //input for date goes here
    $html .= '<input type="date" name="expiry_date" id="expiry_date" value=""  class="input_types"/>';
$html .= '</div>';

echo $html; }