Hello,
I'm converting a HTML/PHP website to wordpress. I'm showing real estate listings on the Google Maps. I've been able to sort out all the problem when converting to wordpress but I'm stuck at a point.

Here is the code;

parameters: function() {
				var result = {};
				var url = window.location.href;
				var parameters = url.slice(url.indexOf('?') + 1).split('&');
 		
				for(var i = 0;  i < parameters.length; i++) {
					var parameter = parameters[i].split('=');
					result[parameter[0]] = parameter[1];
				}
				return result;
			}

Here are the details;

The page URL is http://domain.com/?page_id=113
I'm doing the AJAX requests to show the listings according to visitor's defined fields.
Actually, the requests will be made like this;
http://domain.com/?page_id=113&low=123&high=324 etc

In my previous script, it was http://domain.com/result.php?low=123&high=324

Now how can I do it in wordpress using slice and split.


Any kind of help will be really appreciated.

Regards

I'm a bit in the dark here in that I don't fully understand the nature of the conversion.

I'm struggling with the question, "how can I do it in wordpress using slice and split".

Wordpress is a PHP application.
Javascript runs client-side.

Are you seeking to do something server-side that was previously done client-side?

You can see how little I understand of your problem.

Airshow

Alright, I try to make my problem clear. Actually, the listings are retrieved from mysql database. Each record contains longitude and latitude values which are retrieved and a marker is is shown on the Google Maps. The data is successfully retrieved on the server side but I'm having problem with the client side when the marker has to be shown.

var parameters = url.slice(url.indexOf('?') + 1).split('&');

What above line doing is that it start taking the first value after ? i.e. result.php?low=123
So, it will take low=123 while result.php is the file which contains database queries to retrieve listing information.

So when its, domain.com/result.php?low=123&high=433
It will take first value as low=123 and split at & symbol and then start taking the values after & ...

In wordpress, I've the URL like this;
domain.com/?page_id=113&low=123&high=334 ------- and so on

Now how can i do the same thing with the above url. I've tried the following code but it still does not work;

var parameters = url.slice(url.indexOf('&') + 1).split('&');

I hope this time I've made it clear...

OK, I understand a lot more now.

I think all you need is my QueryParser (fully documented).

With QueryParser installed, you can access the parameters passed in the query string as: $q.page_id , $q.low , $q.high .

Airshow

Hello,
I'm converting a HTML/PHP website to wordpress. I'm showing real estate listings on the Google Maps. I've been able to sort out all the problem when converting to wordpress but I'm stuck at a point.

Here is the code;

parameters: function() {
				var result = {};
				var url = window.location.href;
				var parameters = url.slice(url.indexOf('?') + 1).split('&');
 		
				for(var i = 0;  i < parameters.length; i++) {
					var parameter = parameters[i].split('=');
					result[parameter[0]] = parameter[1];
				}
				return result;
			}

Here are the details;

The page URL is http://domain.com/?page_id=113
I'm doing the AJAX requests to show the listings according to visitor's defined fields.
Actually, the requests will be made like this;
http://domain.com/?page_id=113&low=123&high=324 etc

In my previous script, it was http://domain.com/result.php?low=123&high=324

Now how can I do it in wordpress using slice and split.


Any kind of help will be really appreciated.

Regards

If your var url = location.href; is in: http://domain.com/result.php?low=123&high=324 format.

Use this:

[B]; eval(url.split("?")[1].split("&").join());[/B]

Now you can access your "low" / "high" values by simply calling:
low and high respectively.

alert(low);
alert("Coords( " + low + " : " + high + " )" );

and consider it - done!

NOTE: depending on data after the question mark (?)- when available, the "page_id" value can be accessed as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.