Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL $_GET will not work

I have a problem I never had and I can't find the reason. I moved my site to another host and now it doesnt "read" the $_GET variables.

I have this url: http://whatever.com/path?filtro=si&provincia=Santa+Fe&localidad=Rosario And if I call this:

$localidad = $_GET['localidad'];
$provincia = $_GET['provincia'];
$filtro = $_GET['filtro'];

echo $localidad;
echo "hola";
echo $provincia;
echo $filtro;

Nothing prints except "hola", so there is no PHP error. Here's my .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Im working on a Wordpres site, perhaps it has something to do with Permalinks or something, Im really lost. Thank you very much, I appreciate your help.

EDIT

I renamed my .htacces so it wont read it and the page broke, so I went to permalink settings in wordpress and set them to

 - Post Name    http://luminias.com/index.php/example-page/

And now IT WORKS, but, now this is thw url:

http://whatever.com/index.php/path/?filtro=si&provincia=Santa+Fe&localidad=Rosario

And it prints all the $_GET, but I need that "/index.php/" gone..

like image 797
Mr. G Avatar asked Dec 16 '14 14:12

Mr. G


1 Answers

Add add_rewrite_tag function in your function.php for all parameter :

function custom_rewrite_tag() {
        add_rewrite_tag('%localidad%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);

And you can call your parameter in template using

$wp_query->query_vars['localidad']

Here is the full documentation

Note that using $_GET on a rewritten URL will not work, even if the rewrite includes the querystring variables. You must use $wp_query.

like image 57
Mitul Shah Avatar answered Sep 30 '22 18:09

Mitul Shah