Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get last insert id in Wordpress

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 4.12k
    Comment on it

    Hello Friends,

    Programmer generally need last insert id for their coding requirement. If you are new in Wordpress and you need to fetch last insert id after insertion. Please follow the code below:

    // Define the DB object
     global $wpdb;
    
    // Define array of inserted data
     $data['first_name'] = $_REQUEST['first_name'];
     $data['middle_name'] = $_REQUEST['middle_name'];
     $data['last_name'] = $_REQUEST['last_name'];
    
    // Insert data into database
    $wpdb->insert('wp_connections', $data);
    
    // Fetch last inserted ID
     $lastid = $wpdb->insert_id
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: