Needing Post ID in Ajax plugin.
-
I am trying to get the id of the currently loaded post in my plugin. I have tried a global $post, $post->ID and it is empty. I assume it has to do with the fact that the plugin must have loaded before the page, therefore, there is no post ID. It is for an ajax request. When the user clicks on a link on that post it will load information. That information requires me knowing what post they are currently on.
function MSC_SP_ajax_handler() { // this function gets the ajax data check_ajax_referer( 'my_nonce' ); // checks for the correct nonce which is set in the enqueue function // I need the post ID here. wp_die(); // All ajax handlers die when finished }If I place this in my plug the page fails to fully load and shows the post id.
add_action( 'the_post', 'set_post_id' ); function set_post_id() { global $post; die("the id: ".$post->ID); }But I cannot pass that to the MSC_SP_ajax_handler function.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Needing Post ID in Ajax plugin.’ is closed to new replies.