Extracting the post_id via the wp_insert_post action (external db query)
i'm writing a little action plugin. everytime a new post is created, a new table should be created in an external db. The name of the table sholud reflect the post_id of the newly created post, but i can0t figure how to pass it.
Here's my code so far (for php purists, forgive me for using old mysql_connect (but adding the flag TRUE to the new_link parameter, i don't have to bother with wpdb globals etc)
function insert_new_table($post_id){
$usernamel = "secret";
$passwordl = "secret";
$hostl = "localhost";
$databasel ="secret";
$connect = mysql_connect($hostl, $usernamel, $passwordl, TRUE) or die("Error");
mysql_select_db($databasel) or die("Error, Cannot locate the database!");
$table_name = 'tablename4'; //with this variable works
$postidl = get_the_ID(); // i'm outside the loop .. so what?
$sql = "CREATE TABLE $postidl (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(255) DEFAULT NULL,
UNIQUE KEY id (id)
);";
$query = mysql_query($sql);
return $post_id;
}
add_action( 'wp_insert_post', 'insert_new_table' );
everything is going smooth using the var $table_name in my $sql query; but i can't pass the post_id of the post that is currently being saved (don't know how to get it!)
Any hint?