Solved

Wordpress AJAX

Posted on 2014-07-21
6
239 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The viewer will learn how to dynamically set the form action using jQuery.

744 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

13 Experts available now in Live!

Get 1:1 Help Now