I have had quite a few questions about this on the WordPress forums as I posted I had created something to do this.
My solution is probably not as good as the plugin author’s would have been but as he/she seems to have not updated the plugin for a while this will have to do for now.
This tutorial will show you how I created a search form to search on Keyword, Salary Range and Location(and any combination of these).
The 1st step we will do is add Salary Range and Location as fields when entering a job.
Login to your WordPress back-end and go to Job Manager > Settings > Job Form Settings. Here you will have a list of fields already contained for your jobs (such as Salary, Start Date etc).
Hit the “Add New Field” link at the bottom of the page and create a new field called “Salary Range”, change the type to “Checkboxes”, enter your salary ranges (each range on a new line) and update the jobs.
The reason we must create a range rather than using the already present “Salary” field is that this field is not a numeric field so searching for a salary of a set amount is very complicated, if not impossible.
Once complete, do the same for “Location” and you should have something like this:
Our next step will be to create our search form. Download the Theme folder for your website (This can be found in /wp-content/themes/your-theme-name/) as we will be creating a new template file to use.
The simplest way to create this file so it matches the rest of your website is to copy the “page.php” file and name it “job-search.php”.
With this new file created, open it in whatever your preferred HTML/PHP editor is (I will be using dreamweaver) and find the line(s) that resemble the following:
The second line (line 6 in this case) may not be present so don’t worry if you can’t find it.
Underneath these lines we will create our form. I will begin by showing you my form and then explaining it bit by bit.
Hopefully this will be fairly self explanatory but we will break it down anyway.
Here is the section of the form where users can select their salary range. As you can see I have hard-coded the ranges rather than outputting the ranges we created in step 1. This is simply due to laziness on my part and as I was expecting this to only be a temporary fix until the later version for the plugin was released with a search feature.
We check the URL string for the salary value (if set) and make this the selected option on the drop down. This is simply to allow the user to run a new search without having to re-select their salary range if they do not wish to.
We can create as many ranges as we created in step 1 but simply duplicating the option and incrementing the value for this.
This works in the same way as the salary drop-down but is for the location. Again, define as many locations as you have in Step 1.
This step of the process is to create the functionality that takes the input from the form and displays the appropriate results.
This code is to be placed below the step 2 code.
As before, I will show you the whole bit of code and then break it down and explain it.
As you can see, that was quite a lot of code and it may look rather daunting but it’s actually fairly simple.
I admit this could really use a re-write but as I stated before, this was only for a temporary fix and written in an hour or so.
Anyway, excuses aside, time to break it down.
1st we focus on the “keyword” field. We trim the value to remove and spaces before or after the search term to maximise the matches returned.
We then check if there is no keyword and if so set the variable to be a space. This is because passing an empty string to our query would break it.
We next set the salary and location variables (if they were selected in the form). The values that we set the salary and location to must match what you input into the back-end EXACTLY. I cannot stress this enough. I spent quite a while assuming the system would save the ‘£’ as ‘$amp;’ and accidentally have an extra space in there.
This is the bit of code I am most ashamed to share. After quite a bit of hacking about I finally got the search working and so simply left it at that and I really should have gone back to clean it up. But feel free to do that yourself.
We check what combination of salary and location are set and create the query we need.
The complicated bit here is the bits that say ‘data8′ and ‘data9′. These are what the plugin has saved the custom fields of salary and location as. This may very well be different for you so sadly you will have to check. The simplest way I found was to create a job with these values set as “##salary##” and “##location##”. I then logged into my control panel, into phpMyAdmin and searched for these values.
Replace these values on lines 46, 50, 62 and 75 in this example.
Finally we output using the usual loop for WordPress.
As you can see we output the location and salary that we do not use in the search. This is, as I said, because salary is actually searching on salary range and I did similar with the location.
Our shortest step by far. Simply place the code below ABOVE that of step 2. This simply defaults our values to stop any code breaking further down.
Another short step. Place this code at the very TOP of the file (above the header, above everything). This registers the file as a new template in your theme.
Step 6 (final step)
Finally we upload our newly created file to our website.
After logging into your WordPress back-end, create a new page and call it what you like and in the template dropdown select the one named “Advanced Search” and publish.
You should now be able the view your search page and get results back.
[please note this is a 1st draft and is in need of re-writing. If you have issues then feel free to post them in the comments below but please be patient as I will be re-writing this]