Using JobRelay data

Developers have the opportunity to use the data passed through to WordPress from JobRelay in any way they wish.

When JobRelay finishes processing a job the data sent from JobRelay is made available to developers to use as they wish.

The JobRelay connector plugin contains an action hook in WordPress which is fired once JobRelay has completed adding the job to WordPress. This action hook, named jobrelay_wpcon_job_inserted_complete is passed the job data sent from the posting service via JobRelay, along with the post ID of the newly created job post in WordPress.

Here are some examples of what you might want to do, one a job has been added to WordPress.

Here are some code examples for a couple of these scenarios.

📔 Developer Note – the code in these examples can be placed in the active themes functions.php file, or better still in a plugin you have running on the site.

Save SEO titles and meta descriptions

In this example, an SEO title is generated based on the job title and location.

<?php
/**
 * Saves a meta title and description for a job within the Yoast SEO plugin.
 *
 * @param Integer $post_id  The post ID of the newly created job.
 * @param array   $job_data An array of data passed from the posting service.
 */
function hd_save_seo_meta_title_description( $post_id, $job_data ) {

	// build the seo title from the job title and location in the job data.
	$seo_title = $job_data['job_title'] . __( ' in ', 'jobrelay' ) . $job_data['job_location'];

	// save the job title.
	// In this example we are saving it as meta data in the Yoast SEO plugin.
	update_post_meta(
		$post_id,
		'_yoast_wpseo_title',
		sanitize_text_field( $seo_title )
	);

	// build the job seo description.
	$seo_desc = wp_trim_words(
		$job_data['job_short_description'],
		150,
		''
	);

	// if the seo desc is empty.
	if ( empty( $seo_desc ) ) {

		// use the long desc trimmed.
		$seo_desc = wp_trim_words(
			$job_data['job_description'],
			150,
			''
		);
		
	}

	// save the seo description.
	// In this example we are saving as meta data in the Yoast SEO plugin.
	update_post_meta(
		$post_id,
		'_yoast_wpseo_metadesc',
		sanitize_textarea_field( $seo_desc )
	);

}

add_action( 'jobrelay_wpcon_job_inserted_complete', 'hd_save_seo_meta_title_description', 10, 2 );

Associate another post with the job

<?php
/**
 * Saves the consultant post ID when a new job is posted.
 *
 * @param integer $job_post_id The post ID of the newly created or updated job.
 * @param array   $job_data    An array of all the job data posted via JobRelay.
 */
function hd_save_consultant_post( $post_id, $job_data ) {

	// if we don't have a contact email in the feed - do nothing.
	if ( empty( $job_data['contact_email'] ) ) {
		return;
	}

	// query for a consultant post, based on the contact email.
	$consultant = get_posts(
		[
			'post_type'      => 'hd_consultant', // change for the name of the consultant post type.
			'post_status'    => 'publish',
			'fields'         => 'ids',
			'posts_per_page' => 100, // if you have more than 100 consultants, increase this.
			'meta_query'     => [
				[
					'key'     => '_consultant_email', // change for the meta key storing the consultant email.
					'value'   => sanitize_email( $job_data['contact_email'] ),
				]
			],
		]
	);

	// grab the last post returned - there should only be one.
	$consultant_id = array_pop( $consultants->posts );

	// if we have no consultant id.
	if ( empty( $consultant_id ) ) {
		return;
	}

	// save the consultant id as meta data against the job.
	update_post_meta( $job_post_id, '_consultant_post_id', $consultant_id );

}

add_action( 'jobrelay_wpcon_job_inserted_complete', 'hd_save_consultant_post', 10, 2 );

⚠️ Please note – if you are sending job data to additional sites to display the jobs, an additional license will be needed for that site, as outlined in the terms and conditions.

If you would like to discuss your requirements regarding this, please get in touch.