-4

So I have this variable of $date = array($year,$month); inside a couple of nested foreach statements. I have a link that when pressed should pass the $date variable over to my functions.php for me to play around with.

I'm using wordpress and so far I understand the link has to work something like this:

$link = admin_url('admin-ajax.php?[$date variable needs to go here]&post_id='.$post->ID.'&nonce='.$nonce); 

Basically my question is how exactly does the link above need to be formatted to send my variable? Also, on the server side, how best to receive that variable?

4

1 回答 1

1

First of all, you can't send arrays directly through GET requests (GET requests are the ones with the parameters visible in the url, in layman terms)

therefore, you should do the following:

$date = "$year-$month"; //example: 2013-09
$link = admin_url('admin-ajax.php?my_date='.$date.'&post_id='.$post->ID.'&nonce='.$nonce);

breaking the url down to the components, in layman terms:

  1. everything before the ? is the server address and the page that needs to be served
  2. everything after is the so-called "querystring", which is a sequence of pairs (A=B) separated by ampersands &.

so, a URL that looks like this

www.example.com/dynamic_page.php?A=B&C=D&E=F

means:

visit www.example.com, fetch the page named "dynamic_page.php" and use the value B for the variable A, the value D for the variable C and the value F for the variable E.

于 2013-09-11T13:27:48.440 回答