Solved

Wordpress AJAX

Posted on 2014-07-21
6
242 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 109

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 109

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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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 109

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The viewer will learn how to count occurrences of each item in an array.

856 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