(In WordPress) How do you pass URL parameters further downstream? - wordpress

I'm running a pest control AdWords campaign.
When people click on an ad and get to my main page, the url has a query string that has the service and the town name
It'll be like pestcontrol.com/pestcontrol?service=roaches&town=Beverly
It's important because I draw from this query string to populate the page heading "Looking for [service] in [town]?"
On my main page, they have to choose the pest that they're having trouble with.
Let's say they pick rodents - it'll send them to the rodent page
But I'll lose the query string...
How can I keep the query string so that the next page can be personalized as well?
Is there some way to write a link so it keeps the current query string?
I'm a noob and I'm new to Wordpress and web dev in general so any help is appreciated

Related

How do I create a new page for each user?

I need to create a new page for each user on signup so when you go to the site's explore page and click on someone's name or picture, it will take you to their specific page and display their data. (database is firebase firestore and firebase storage, saved link to each person's doc)
This is one of the issues I've been trying to fix for about a month(just fixed the explore page issue and got everyone profile pic to display with that individual user's name right below). I have tried making a new html page with someone's php and js script (didn't work, not familiar with php) and url rewriting.
I haven't been able to find anything else concrete or at least something else to point me in the right direction. Any pointers or tips?
(Vanilla/node.js)
With PHP, on clicking a persons username you can add the username as a parameter to the url e.g yoursite.com?user=personsusername then use GET method to retrieve the username and output data relating to that username from the database

WordPress search widget native constructing different query string on relative pages

I am a beginner Wordpress developer and am developing a WordPress search plugin with some AI based API involved.
How does plugin work?
User fire some search in search widget
If the query text is identical to AI based API we get some textual result and relevant URL (within site) to redirect the page.
If query text is strange or beyond AI's scope of identification then we invoke search widget submit. By calling 'el.submit()' JS method.
What is the problem?
My plugin is working as expected on the home page. Ex www.example.com
If I search 'Google search console' (Which is an internal article) then search widget invoking the native search and search widget submits the form. URL becomes www.example.com/?s=Google+search+console.
Problem: When I go to www.example.com/blog and fire the same search query then URL becoming www.example.com/blog/?s=Google%20search%20console
Resulting in 'Page not found'.
It is weird. Do somebody had any idea what is happening here or why two different constructs of a search query on relative pages within the site.

Escape a Shebang /#!/ in URL for Google URL Builder

Does anyone know if/how I can escape the shebang or encode the uri to make a link work properly in google analytics url builder? I want to add campaign parameters to product page urls to track ads success. The url for each individual product page looks like this:
http://www.oursite.com/classic-movies/#!/Title-of-Movie/p/12345678
When I put the product page url into the url builder, it says the url is invalid. I think it is because of the #!. I have tried escaping out the special characters, replacing the shebang with %23%21 or %21!
It appears valid in the url builder, and the builder generates a link with utm tags, BUT when you paste the tagged link into the browser, it does not take you to our product page. It takes you to our website, but gives a "sorry does not exist" message.
I also tried this:
http://www.oursite.com/classic-movies/?_escaped_fragment_=/Title-of-Movie/p/12345678
It generates a link in the builder and does link to the product page of our website (yay!), but the url adds this after the campaign name: #!/Title-of-Movie/p/1234567
The shebang is back! Will that be a problem?
For reference, we're using the Ecwid storefront plugin for a wordpress site.
Thanks in advance.
Short answer
You should use the URL without fragment (hash part) as a base for building URLs with queries (the part starting with '?') and then append the hash part to the end of URL.
Example:
1) Take http://www.example.com/classic-movies/#!/Title-of-Movie/p/12345678
2) Remove hash part: http://www.example.com/classic-movies/
3) Use this hash-free URL as a base and add query parameters yourself or use any automatic builder. Example: http://www.example.com/classic-movies/?utm_source=myblog&utm_campaign=xyz&abc=def
4) Append the hash part to the end of the URL: http://www.example.com/classic-movies/?utm_source=myblog&utm_campaign=xyz&abc=def#!/Title-of-Movie/p/12345678
You're done – the final URL is valid URL which will work fine for browser/customer, your site server and tracking tools like Google Analytics
Long answer
1) URLs could be very different, but their structure is actually quite the same and that's a part of the web standards.
URL is built this way:
protocol://site/path?query#fragment
(I simplified it and take in consideration only the parts we're talking about, the actual scheme is a bit more complicated)
Taking your product page URL, that will be:
protocol: http
site: www.example.com
path: classic-movies/
query: (empty)
fragment: !/Title-of-Movie/p/12345678
Now, if you want to add query parameters, you know where to insert them. As to the fragment part, it should be always in the end, regardless of whether it contains !
2) Google Analytics doesn't track the fragment parts of the URLs.
Urls like http://www.example.com/coolpage and http://www.example.com/coolpage#!anyparameter=anyvalue are the same for Goolgle Analytics. That's likely the reason why their URL builder tool doesn't accept that.
By the way, Ecwid uses fragment part of the URL all the time to address the product and category pages, but that's not an issue if you want to track your product pages in Google Analytics. Ecwid solved that problem by sending special 'virtual' page views to Google Analytics every time a customer browses your store. So in your GA reports you will see your store pages.
3) If you use Google Adwords for your ad campaigns, I'd suggest linking your Google Analytics and Google Adwords profiles to have better picture of customer behavior and the campaign performance. Check out this thread on Ecwid forums for the details:
http://www.ecwid.com/forums/showthread.php?t=10835

Search Engine Optimization: How do sites like Yellow Pages get all their listings found by search engines

I am trying to build a locally-based restaurant listing/reviews site. I can't help but notice that if I search for a restaurant on the web that sites like Yellow Pages or Yelp have a listing that appears at the top of the list for that restaurant. Obviously they don't have a separate web page for every restaurant in the US, but somehow their database of info is being read by the search engine. How is that accomplished?
Thanks in advance.
The information is stored in a database, and a template page just pulls up the information from the database and displays it. The URL appears to be a unique page for the restaurant by clever use of URL re-writing or, in .NET, using routing.
Routing basically takes a GET parameter from the url, incorporates it into the URL as a pseudo-path, then uses that parameter to get the database record to display the restaurant.

Adding an sql query to the end of a wordpress permalink?

Ok....so I created a new wordpress theme and I still can't get my custom code to work.
I want to be able to have a page which will output a list of items from the database, each item will have this URL format:
www.site.com/category/subcategory/?id=XX
The ?id=XX query should be at the end of the URL and will direct the user from the category page to the subcategory page showing specific data about the item with the XX id.
Each item in the list is wrapped in an tag in the category template page and the subcategory page uses $_GET. I've got one wordpress theme that works but on my other site, I use a different theme and it doesn't work. If a user clicks on an item in the list, the user gets directed to the subcategory page without the sql string attached. I'm not sure what to put in the functions.php file in wordpress (or whatever the file is called that handles functions) or in the htaccess. Any help is appreciated.
Update:
#Niels - I didn't make the code...I had two people make the code for me. Neither of them are professional coders but they got it to work so that's all I cared about. My website has never been hacked before but I need to find out how to get the code to work myself since the two guys who created the code are busy nowadays. Yea, I've been told about the sql injection.
I've got php code on the category page (http://www.mysite.com/category) that defines variables that will be used in the code, connects to the database, queries the database table, and then selects and outputs the items in the database table using the id of the item. The code uses a while loop to output the items so that the category page is basically a directory of items. Each item that gets outputted is outputted in this format: $itemname. Like I said, the code already defines these variables at the very beginning so the sql query already knows what to look for. When a user clicks on any item in the category page, the link should take them to the item's profile page, which is basically the subcategory page (ie: http://www.mysite.com/category/subcategory/). So let me be clear: when a user CLICKS on an ITEM in the CATEGORY PAGE, the user should be directed to the item's profile page, which is basically the SUBCATEGORY PAGE. This is where the /?id=$id part comes in. During the transition phase from category page to subcategory page, the query string should attach itself to the URL and the subcategory page will output data based on the data that is in the database for that specific item. For instance, if a user clicked on a link such as this: www.mysite.com/category/subcategory/?id=12, the user should be directed to the profile page of the item with the id of 12. The profile page, which is the subcategory page in our case, should output data for the item in the database that has the id of 12. That's how it should work. The subcategory page, or item profile page, will have a $_GET code so that it knows what data it is suppose to output.
Revised Answer
Look into WordPress' Rewrite API. It's definitely the more "correct" way of doing this.
Original Answer
Instead of using a URL query, try something like:
// URL: http://blahblahblah.com/category/pagetitle/15
preg_match_all('/[^\/]+/', $_SERVER['REQUEST_URI'], $matches);
$item_id = $matches[0][2];
echo 'Do whatever you want with Item ID ' . $item_id;
If a user clicks on an item in the list, the user gets directed to the
subcategory page without the sql string attached.
What do you mean exactly with "sql string"?
Could you describe, as concrete as possible, what links you have, examples and what page they should direct to and what those pages should do?
Also: I get the feeling you're a little out of your depth here and you're doing stuff with the database based on parameters from the URL . You should know that manipulating URL parameters to gain access to a database is a real easy way to hack a site. Please read a little bit about SQL Injection and how to prevent it.

Resources