When trying to get the id of an authorized user wordpress gives 0.
<?php
$title = $_POST['title'];
$start = $_POST['start'];
try {
require "db_config.php";
require "wp-includes/user.php";
} catch(Exception $e) {
exit('Unable to connect to database.');
}
$cur_user_id = get_current_user_id();
$sql = "INSERT INTO events (title, start, cur_user_id) VALUES (:title, :start, :cur_user_id)";
$q = $cal_db->prepare($sql);
$q->execute(array(':title'=>$title, ':start'=>$start, ':cur_user_id'=>$cur_user_id));
?>
CodePudding user response:
you can try this
$cur_user_id = wp_get_current_user();
CodePudding user response:
Put my code in a new folder in plugins and activated in wordpress, everything worked. https://wp-kama.ru/id_2018/ajax-v-wordpress.html