I am trying to get last inserted data from WP database but it shows nothing.
code :
global $wpdb;
$lastid = $wpdb->insert_id;
$table = $wpdb->prefix."videos";
$result = $wpdb->get_results("SELECT * FROM $table WHERE id = '$lastid'");
foreach ( $result as $print ) {
echo '<tr>';
echo '<td>' . $print->video.'</td>';
echo '</tr>';
}
Please advise.
From the Codex (emphasis mine):
It only makes sense to use
$wpdb->insert_id
after an insert statement. Otherwise it won’t be set.Depending on your table and your requirements, something like:
might do what you need.