Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

variable js in php (fee increased) WordPress


on my wp site, i display a sentence like, this for example, if you are in Lower-Normandy :
"Vous êtes en Basse-Normandie. Il y a trois magasins dans votre région".
(translation : "You are in Lower-Normandy. There is 3 shops in your region.").

The number of shops is displayed by a loop with this arguments :
$args = array (
'posts_per_page' => -1,
'post_type' => 'shop',
'meta_key' => 'regionmap',
'meta_value' => $region

The variable $region comes probably from a js like this
function initialize() {
var adr2 = "";
var lat = google.loader.ClientLocation.latitude;
var longi = google.loader.ClientLocation.longitude;

var latlng = new google.maps.LatLng(lat, longi);
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'latLng': latlng}, function(results, status) {

if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {

var elt = results[0].address_components;

for(i in elt){
if(elt[i].types[0] == 'administrative_area_level_1') gmap_region=elt[i].long_name;
adr2 = gmap_region;


jQuery(document).ready(function($) {

But i don't know how use the js variable (region) like a php variable.
Probably with ajax...

Could you write the complete code ?
Thank you very much.

Answers (2)


Francisco Javier Carazo Gil answers:

You can do directly:

'meta_value' => <?php echo $region; ?>

Francisco Javier Carazo Gil comments:

But you will have to load this JS in a PHP file.

Francisco Javier Carazo Gil comments:

But you will have to load this JS in a PHP file.

Sébastien | French WordpressDesigner comments:

ok... could you write this js please ?

Sébastien | French WordpressDesigner comments:

Francisco : here is the page returning the region [[LINK href=""]][[/LINK]]

How can i use the region in a php loop ?

Francisco Javier Carazo Gil comments:


Could you send me the file that you are using and I told you how to do it.

Send me a PM and I will send my mail.


Sébastien | French WordpressDesigner comments:

@everybody : this question is not closed :-)
if you have a response, i could increase my fee.


Ptipwa answers:

Hi Sébastien,

Send me a PM and I'll send you an email to resolve this problem.


Sébastien | French WordpressDesigner comments:

Ok ptipwa, thaks for your help. I send you my email by PM

Sébastien | French WordpressDesigner comments:

thanks a lot for your help Ptipwa !!