JohnG
JohnG

Reputation: 497

GET Request not working in WordPress

I'm trying to pull a string from my URL in WordPress, and create a function around it in the functions file.

The URL is:

"https://made-up-domain.com/?page_id=2/?variables=78685,66752"

My PHP is:

$string = $_GET("variables");
echo $string;

So I'm trying to return "78685,66752". Nothing happens. Is the first question mark a problem? Or what am I doing incorrectly? Thanks!

Upvotes: 0

Views: 2804

Answers (4)

Levente Otta
Levente Otta

Reputation: 795

Your URL should be like:

https://made-up-domain.com/?page_id=2&variables=78685,66752

instead of:

https://made-up-domain.com/?page_id=2/?variables=78685,66752

& char is separating the queries in URL.

And you have syntax error. Use $string = $_GET["variables"]; because $_GET is a superglobal array, not a function.

Use $variables = explode(",", $string); separate values into an array if you want. Simplier way is $variables = explode(",", $_GET["variables"]);

Upvotes: 1

Gooner
Gooner

Reputation: 369

You should format your href and get parameter like this

http://example.com/mypage.html?var1=value1&var2=value2&var3=value3

+ Edit your get method syntax

$string = $_GET['variables'];

Upvotes: 0

Kasia Gogolek
Kasia Gogolek

Reputation: 3414

$_GET is not a function but an Array so correct way of reading it is

$string = $_GET['variables'];

You are also creating the query string all wrong, you should be using

?variables=123,456&page=1

Read more about $_GET here http://php.net/manual/en/reserved.variables.get.php

Upvotes: 1

samo0ha
samo0ha

Reputation: 3796

$_GET should be in the form

$string = $_GET["variables"]; 

and not

$string = $_GET("variables");

Upvotes: 2

Related Questions