Check out JobRelay, our new improved product for integrating WordPress with job posting and distribution software such as Broadbean, LogicMelon and Idibu. It is faster to integrate cheaper and uses a more modern approach.
A few months ago one of our biggest clients came along with a request to integrate the BroadBean Job posting solution into their website. Of course I had built the recruitment website using WordPress in order to for them to post jobs to their site and enable them to recruit people to specific jobs etc. As part of the build it was important that as well as being able to post jobs to the site using the normal WordPress way (writing posts etc) they wanted to be able to use external sources to post to their site too, in this case Broadbean. Here is how I went about this with help from colleague David Hassen.
Let me outline first what Broadbean actually is and how it works. Recruitment companies need to get their job posts out to a wide variety of clients across the UK and beyond and therefore as well as posting jobs to their own website they need to tap into other job posting sites. This means a lot of repetition in terms of writing the advertisement on all of these sites. This is were the Broadbean system comes in. With it, you write one job listing and then Broadbean system sends this job to many of the jobs sites including your own website. It was the later which myself and colleagues needed to integrate into the clients WordPress site.
Broadbean provide you with either an XML feed or a they use the PHP Post method in order to send the completed job form to your site. Therefore we designate a URL to which this ‘feed’ is sent to and then at this URL we need some code to interoperate this feed and then add a post to our WordPress site including the information in the feed.
As we were using the post method the first stage of this was to get the value from the posted information and separate them, storing each as PHP variables. In the example below, we are assuming that there are 4 pieces of information that are sent. These are the job title, job category, job description and job type (part time or permanent etc.). To start with we grab the information and store it as variables like this:
[php]
$pj_jobTitle = $_POST[“job_title”];
$pj_jobCategory = $_POST[“job_category”];
$pj_jobDescription = $_POST[“job_description”];
$pj_jobType = $_POST[“job_type”];
[/php]
The variables names prefixed with ‘pj_’ are the names I have chosen to store the values in. Always prefix you variables names to avoid clashes in your system. In the square brackets above are the names of the values sent by Broadbean (they will ask you for these when you set up this system).
Now we have the information, we need to add this to our WordPress website, probably as a post. To do this we make use of the wp_insert_post()
WordPress function. Before we get into that lets think about each piece of information and how we would add it to a WordPress post.
To start with the Job Title (we have this as the variable $pj_jobTitle
) can be added as the title of the post. The job category will be added as a post category and the job description will be added as the post content. The job type will need to be added as a custom field (meta data) to the post once we have created the post. First lets create a new post using job title, job category and job description. This is where the wp_insert_post()
comes into play and we do it like this:
[php]
// create post object
$pj_post = array(
‘post_title’ => $pj_jobTitle,
‘post_category’ => array($pj_jobCategory),
‘post_content’ => $pj_jobDescription,
‘post_author’ => ‘4’,
‘post_status’ => ‘publish’,
);
// adds the post and return the post id to this variable
$pj_jobpostid = wp_insert_post($pj_post);
[/php]
The first part here we simple create a variable that stores all of our post data as an array (all except our custom meta data – the job type). The second part using the wp_insert_post()
adding our variable containing the post data to the function. The wp_insert_post()
function, when successful returns the ID of the post that is created so we are going to store this ID (we will need it to add the meta data) in the variable $pj_jobpostid.
Now we can add the job type as a custom field. To do this we are going to use the add_post_meta()
function. This adds a custom field to a post given the posts ID (in our case $pj_jobpostid
) the custom field key (in this case pj_job_type) and the value you want for this custom field (in our case $pj_jobType
. This is added using the following code:
[php]
if($pj_jobpostid != 0) {
add_post_meta($pj_jobpostid, ‘pj_job_type’, $pj_jobType, true);
}
[/php]
We wrap this code in an IF statement that basically says if the value of $pj_jobpostid
is anything but 0 (i.e. the wp_insert_post()
has worked) then add our custom field.
The final thing to do is to give the user and Broadbean some feedback in order to check whether the whole process has worked. To so this we can add to our IF statement above something like the following:
[php]
if($pj_jobpostid != 0) { // if adding job is successful
add_post_meta($pj_jobpostid, ‘pj_job_type’, $pj_jobType, true);
echo ‘Nice one! The job has been added.’;
} else { // if adding the job failed
echo ‘There has been an error adding the post to the database!’;
}
[/php]
So there we have it. A system that allows you to use Broadbean in order to add jobs to your WordPress website as posts.
Leave a Reply