Getting the post_id in wp_ajax function

Its an old question however would like to answer for other people

Within ajax function hooked to wp_ajax do this.

$url     = wp_get_referer();
$post_id = url_to_postid( $url ); 

Leave a Comment