0

I have created a custom table to save post data from custom meta box

And I have a problem in saving data from custom meta box to custom table

so this is my function save_meeting_meta_box()

function save_meeting_meta_box($post_id)
{
    if (!isset($_POST["meta-box-nonce"]) || !wp_verify_nonce($_POST["meta-box-nonce"], basename(__FILE__)))
        return $post_id;
    if(!current_user_can("edit_post", $post_id))
        return $post_id;
    if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE)
        return $post_id;

    $slug = "post";
    if($slug != $post->post_type)
        return $post_id;

    $meta_box_text_value = "";
    $meta_box_dropdown_value = "";
    $meta_box_checkbox_value = "";
    $th_pax = "";
    $th_half = "";
    $th_full = "";
    $Theater = "Theater";
    $ClassRoom = "Class Room";
    $U_Shape = "U - Shape";
    $RoundTable = "Round Table";

    if(isset($_POST["th_pax"]) && isset($_POST["th_half"]) && isset($_POST["th_full"]) )
    {
        $th_pax = $_POST["th_pax"];
        $th_half = $_POST["th_half"];
        $th_full = $_POST["th_full"];
    }  
    insert($wpdb->prefix.'meeting_options', array(
                        'post_id' => $post_id, 
                        'post_setup' => $Theater,
                        'post_pax' => $th_pax, 
                        'full_price' => $th_full,
                        'half_price' => $th_half  
                    )); 
}

add_action("save_post", "save_meeting_meta_box", 10, 3);

So how can I insert data values of custom metaboxes into a database to specific table ?

I don't know if I should use update_post_meta() to insert data in custom table instead of wp_postmeta

  • You're going to have to use MySQL - Wordpress has a built-in database object to work with - View Codex – Howdy_McGee Apr 2 '15 at 17:04
1

try getting the values with the POST, then you can try this

$wpdb->update('meeting_options', array(fieldsGoHere);

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.