Blog

Development Category

Creating an Advanced Job search for the Jobman WordPress Plugin

February 7th, 2012

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).

Step 1

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:

Step 2

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.

 Step 3

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.

Step 4

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.

Step 5

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.

 

Download Code Example

 

[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]

Read More

Google’s Native Client Gets Gaming

January 3rd, 2012

For those of you who don’t know about Google’s Native Client then let me take a moment to enlighten you.

Native Client is Google’s SDK that is now present in all versions of Chrome on desktops, whether it be Windows, Mac, Linux etc. This SDK allows your browser to run “Native Code” such as C, C++ and C#. Until now a browser’s main task has to be to read HTML and display it to you in a pretty way. With the addition of “addons” such as flash this functionality was extended to things such as rich media and video. Now, with the power of Native Client you browser can be the source for all your software needs.

Imagine a world where instead of having to install office you simply opened an “app” in Chrome that streamed this functionality to you. Always up to date, always with the latest features. Well this is what is now on offer.

The area I find more interesting is games. These are by far some of the most demanding pieces of software around. It’s very rare you’ll hear someone say “I best get a new PC as I don’t think it’ll run the new MS Office” but you often hear people talking this way when it comes to games. As Native Client has full access to all your hardware (graphics card included) your browser is now capable of running the most powerful games your PC can handle. Not only that, but they are cross-platform compatible. No more coding another version for Mac, simply code it once and you have it available to all.

Well, the revolution has begun. The popular Indie game Bastion (which I own and enjoyed a lot) had made the leap and is now available in your browser. It’s still 40MB or so but if you;re interested and have Google Chrome then I suggest giving it a go!

 

Play Bastion

 

Read More

Google Starts Throwing Darts

October 11th, 2011

Yesterday (sorry for being a bit late) Google released the first iteration of it’s new scripting langue Dart (originally called Dash). The aim of Dart is to replace Javascript as the built-in scripting language for browsers.

Currently only Chrome, Firefox 4+ and Safari 5+ are supported (or support it more to the point) but Google is working hard to increase that list. After all, what good is a language that only some people speak? *cough* If they can get IE on side (no easy task as Web standards have shown [screw you IE 6!]) then I can honestly see it taking off. After reading the documentation and trying a few tutorials is does seem intuitive and easy to write. After all, for Javascript to be worth using these days you have to use jQuery or an equivalent so why have the middle man?

Google is also planning on cramming a Virtual Machine into it’s popular web browser Chrome for Dart and is hoping other browsers will do the same, and the way they all seem to be copying Chrome at the minute I don’t see any but Microsoft having a problem with doing just that.

 

Visit Dart Website

Read More

Home