Mapping JobRelay fields to WordPress data

Data arrives at your WordPress site from JobRelay through the JobRelay endpoint. You can see a full list of the data by viewing the JobRelay field listing.

When the data arrives, the JobRelay connector plugin will attempt to save this data in WordPress, based on the mappings created in the plugins settings screen.

This article outlines how to create mappings to make sure the data is saved as you want it, in the correct place in WordPress. Mappings are required, because everyone’s WordPress site is different. Some may have a bespoke job board solution, whereas others will have used something off-the-shelf.

How can I save the JobRelay data?

When a job arrives, a new post is created in WordPress. This post is created in the post type entered on the sites settings screen. The additional data, sent with the jobs, for example salary, can be saved in one of two ways:

  1. Post meta – the values can be saved as meta data, stored against the newly created job post.
  2. Taxonomy terms – the values can be saved as specific terms in a given taxonomy. If the term does not exist already, it is created first and then assigned to the job.

Meta mappings

Meta mappings, is where we tell JobRelay which values, from the feed of job data, we want to save as meta data (custom fields), and which meta keys to save them as.

Meta mappings are entered in the JSON format and consist of a key and value pairing. The key is the meta key to save the value against and the value is the name of the field in the JobRelay feed.

Take a look at this example:

{
    "_salary":"salary"
}

This instructs JobRelay to save the value sent over in the salary field as meta data using the meta key named _salary.

You could output this in your WordPress templates like this:

<?php
// get the salary value from post meta.
$salary = get_post_meta( $post->ID, '_salary', true );

// if we have a salary value
if ( ! empty( $salary ) ) {

	// output the salary.
	?>
	<div class="salary"><?php echo esc_html_e( 'Salary:' ); ?> <?php echo esc_html( $salary ); ?></div>
	<?php

}

Taxonomy mappings

Instead of saving data as meta data, you may want to save it as terms within a given taxonomy. This makes sense if you want to more efficiently search for jobs based on this data.

Like the meta mappings, taxonomy mappings are also added in the JSON format and consist of a key value pairing. The key is the taxonomy name and the value is the name of the field in the JobRelay feed.

Take a look at this example:

{
    "job_listing_category":"job_industry"
}

This instructs JobRelay to save the value sent over in the job_industry field as a term in the job_listing_category taxonomy. The connector plugin checks to see if there is an existing term with the sent value as its name. If there is that term, gets assigned to the job. If no terms exists with that value, a new term is created before being assigned to the job.

⚠️ Developer note

Remember when working with JSON, the key and value must be wrapped in speech marks with a colon between. Each element of the JSON should end with a comma, except the last element which has no comma.

It is recommended that you write out your JSON in a code editor as it will help you with formatting and most importantly highlight any syntax errors for you. You can then copy and paste this into the JobRelay settings screen.

What about the job title, description and short description?

These are always saved for each job without the need to map the data. This is because the job title is saved as the job post title (post_title), the job description saved as the job post content (post_content) and the short description saved as the job post excerpt (post_excerpt).