Solved

Wordpress AJAX

Posted on 2014-07-21
6
240 Views
Last Modified: 2014-07-22
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

0
Comment
Question by:stargateatlantis
  • 3
  • 2
6 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40210186
What is the purpose of line 6?
0
 

Author Comment

by:stargateatlantis
ID: 40210203
it was in the tutorial link I just copied it from there
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40210235
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:stargateatlantis
ID: 40210404
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.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40210444
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?
0
 
LVL 28

Accepted Solution

by:
chilternPC earned 500 total points
ID: 40210449
check out the wordpress forum  this is similar and may shed some light

http://wordpress.org/support/topic/ajax-function-not-returning-any-results
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now