I am trying to create a plugin that can relate two posts to each other, and to do so I am trying to use AJAX, but I am having trouble getting the current posts ID using $post->ID
.
I am trying to relate custom post types that I created to each other, and when I tested the AJAX it worked flawlessly.
here is the code,
function eu_database_return(){
global $wpdb;
global $post;
if(isset($_POST)){
//insert the relation into the database
$wpdb->insert('eu_relations', array('id' => NULL, 'item_id' => $post->ID, 'related_item_id' => $_POST['post_id']));
}
echo 'added into the database';
die();
}
that is my AJAX function to save the data into the database, any idea what I am doing wrong?