0

I want to get last inserted id to update table based on this id. For that I used $wpdb->insert_id for getting the last inserted id. But get this issue Notice: Undefined property: wpdb::$insertid in D:\wamp\www\wordpress-4.7.1\wordpress\wp-includes\wp-db.php on line 684

this is my code. Someone please help

$parent_id=$template_load_data['id'];
         $wpdb->insert( 'wp_rxl_templates', array(
                'template_name' => $_POST['template_name_custom'],
                'template_content' => $post_content,
                'created_date' => current_time( 'mysql' ),
                'status' => 'active',
                'default_template'=>'false',
                'parent_template_id'=>''.$parent_id.'',
            ));
            $result_id = $wpdb->insertid;
 $result_data = "select wp_rxl where status ='active' NOT (id = '$result_id')";
Meera S Nair
  • 35
  • 1
  • 1
  • 8

1 Answers1

0

You have wrote it as wrong. Check below:

You have to use $wpdb->insert_id instead $wpdb->insertid.

$parent_id=$template_load_data['id'];
         $wpdb->insert( 'wp_rxl_templates', array(
                'template_name' => $_POST['template_name_custom'],
                'template_content' => $post_content,
                'created_date' => current_time( 'mysql' ),
                'status' => 'active',
                'default_template'=>'false',
                'parent_template_id'=>''.$parent_id.'',
            ));
            $result_id = $wpdb->insert_id;
 $result_data = "select wp_rxl where status ='active' NOT (id = '$result_id')";
Virb
  • 1,639
  • 1
  • 16
  • 25