I have a plugin that I'm working on and I'm having trouble getting the post id so jquery can use it. I'm able to get it using the admin_head hook but I'm not sure how I can return it to jquery. I'm not sure if admin_head is what I need since it does not return anything. Not sure if I can use global?
Also this is in the admin screen so not on the front end.
Here is what I have so far:
$custom_ID = 0;
function my_custom_admin_head(){
global $post;
$custom_ID = $post->ID;
global $custom_ID;
}
add_action('admin_head', 'my_custom_admin_head');
add_action( 'admin_footer', 'my_action_javascript' );
function my_action_javascript() {?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
$('#get-rates-button').click(function(){
var result = "<?php echo $custom_ID; ?>";
alert(result);
}
}
Is there a function that I could call from jquery that would be able to return the id from a hook or does someone know of a better way?
Thanks!