Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

482
Views
Get current post id from front end via ajax wordpress
function sendIdToFrontend(){
  global $post;
  $postId = array('post_id' => $post->ID);
  die(json_encode($postId));
}

This is my ajax function, I am at single post page. Where I've button which triggers this function. But I'm unable to get the post id. Is there anything wrong with this function ? I'm getting "null" in response.

jQuery.ajax({
  url: ajax_object.ajaxurl,     
  type: 'POST',
  dataType: 'json',
  data: {'test': 'test', action: 'checkCorrectAnswersViaAjax'},
  success: function(response){
    console.log(response);
  },
  error: function(err){
    console.log(err);
  } 
});
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!