Search Form problems
-
I have a few problems with the search form not working properly in that it does not search the site that I want it to search but first some background info below.
I have two websites: mycompany.org (which I do not manage or have any control over so let’s call it site A) and mydepartment.mycompany.org (which I am responsible for, let’s call it site B). Both of these sites are on separate servers and therefore separate wordpress installations. I am not sure what the version of wordpress that site A is running on but my site (site B) is running on the latest version.
The folks that control the top level domain site A have imposed the same theme template on all subdomain sites. Therefore I have to use the theme that they have given me. The search form in their theme seems to allow the user to choose to either search our site or the main company site (site A) by making a radio button selection. The theme that they have given me contains a search.php page under the wp-content/themes/theme-name/forms directory. It currently looks like this:
[Code moderated as per the Forum Rules. Please use the pastebin]
When we applied the template to our site it did not work. By that I mean that when we tried to search for something it would only search site A and not my site B. It was critical for us to get the search working on our site so I made a couple of changes for this to work. Here is the new code which will now work to only search our website (Site B) and not the Site A website. I am only including the area where I made changes.
<form id="searchform" action="" method="get" accept-charset="UTF-8"> <div style="font-size: 90%; color: #eee;"> <input type="text" class="text-input" id="s" name="s" size="20" tabindex="1" accesskey="S" value="<?php echo htmlentities($_GET['s']); ?>"/> <input type="submit" class="submit-button" id="searchsubmit" name="searchsubmit" value="" tabindex="2"/><br/> </div> </form>
It seems that by default WordPress uses the ‘s’ variable for searching but the template that they had given me used the ‘q’ variable instead. So I obviously had to change that. I also removed the radio button options because after making the change from ‘q’ to ‘s’ it didn’t matter what the user selected it would only search our site.
My problems and questions are:
1. At one point in the future I will need to put that radio button choice back in to allow users to either search our site (by default) or the main company site. How would I achieve this? When I go to https://www.mycompany.org and I run a search, I pay close attention to the URL bar and it looks like this: https://www.mycompany.org/search/index.asp?q=forms when I run a search on my website it looks like this: https://mydepartment.mycompany.org/?s=forms&searchsubmit= Notice how theirs uses ‘q’ and mine uses ‘s’. Does this mean that I will have to change all references in my wordpress installation files from ‘s’ to ‘q’ in order for the search to work on my site and to also be able to pass the search on to the company’s main site when a user chooses to do so by using the radio buttons? I looked into doing this but it seems that I would have to change this in quite a few places outside of the theme files (ie. query.php. classes-wp.php, etc.). This concerns me because if there is an update/upgrade for wordpress that gets released later on that changes these files back to using ‘s’ it will break this functionality. Is there a good way to do this?
2. I’ve noticed that when I run an empty/blank search on my site I get a blank page with obviously no results. But when I do this on other websites it just refreshes the page or returns the user to the home page. How would I go about doing this?
Thanks for your help!
- The topic ‘Search Form problems’ is closed to new replies.