Link to home
Start Free TrialLog in
Avatar of stargateatlantis
stargateatlantis

asked on

Wordpress AJAX

I am following the code here  in my wordpress template

http://www.benmarshall.me/wordpress-ajax-frontend-backend/

But the problem is in my_action_callback i am trying to get the post or page id as the return value but it isn't working.  Any ideas as to what i am missing.  

// The function that handles the AJAX request
function my_action_callback() {
  check_ajax_referer( 'my-special-string', 'security' );
  global $post;
 
  $whatever = intval( $_POST['whatever'] );
  echo $post->ID;
  die(); // this is required to return a proper result
}

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

What is the purpose of line 6?
Avatar of stargateatlantis
stargateatlantis

ASKER

it was in the tutorial link I just copied it from there
But what is it supposed to do?  I would not encourage anyone to copy tutorials without understanding the moving parts.  It doesn't make sense to me out of context (and it might not make sense in context, either).  Does it have a purpose that you understand?  I ask because it seems to assign a value to a variable that is unused in the function.  When I see something like that, that does not seem to make any sense, it's a code smell and I call the whole piece of programming into question.
its a Ajax call within wordpress.  I think we are loosing ground on the original question.  I am not sure if you are familiar with it's back end or what you can do.
I understand PHP fairly well and understand WP at a journeyman level.  The code snippet evinces a technically incompetent concept.  Maybe if you can step back from trying to use this example and give us the "big picture" of the application in non-technical language we can help.  But please don't install any script you do not understand -- that's a recipe for confusion at every level.

I won't ask why you chose this particular programming example.  What are you trying to make happen?
ASKER CERTIFIED SOLUTION
Avatar of Peter Hart
Peter Hart
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial