do_action( ‘jobrelay_wpcon_job_inserted_complete’, $post_id int, $job_data array)

In this article

Fires once a job has been created from data sent over by the posting provider and all the meta and taxonomy terms have been added.

Parameters

More information

The hook fires once the entire job including all its mapped meta and taxonomy terms have been saved against the job.

This is a good hook to use in order to carry out any further tasks on a job which has been successfully saved.

Example usage

Save a team member post as meta against the job

Save a team member post as meta against the job

Often a site may use a custom post type to store team members or consultants. Each consultant then would have their own page in WordPress using the single template for the custom post type.

To associate a particular team member with a job, you may want to store the post. ID of the team member post that represents the consultant that posted the job.

To do this we can use the contact_email field in the JobRelay feed, which should be the consultants email address. When the job is posted we can find the team member post that has the same email address and save it the post ID against the job.

Here is some code that would do this:

<?php
/**
 * Save the consultant post ID against the newly created job.
 *
 * @param integer $post_id  The newly created job post ID.
 * @param array   $job_data An array of the job data sent.
 */
function jobrelay_save_team_member( $post_id, $job_data ) {

	// if we don't have a contact email address.
	if ( empty( $job_data['contact_email'] ) ) {
		return;
	}

	// find the team member post which has this email.
	$team_members = new WP_Query(
		array(
			'posts_per_page' => 1,
			'post_type'      => 'team_member',
			'fields'         => 'ids',
			'meta_key'       => 'email_address',
			'meta_value'     => sanitize_email( $job_data['contact_email'] ),
		)
	);

	// get he returned posts array.
	$team_members = $team_members->posts;

	// if no team members are returned.
	if ( empty( $team_members ) ) {
		return;
	}
	
	// update the meta to store the team member.
	update_post_meta( $post_id, '_team_member_id', array_shift( $team_members ) );

	// reset the query.
	wp_reset_postdata();

}

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

The team member post type in this instance is called team_member and we are saving the post ID of the team member found as meta data against the job with the meta key of _team_member_id.

You could place this code in either your themes functions.php file or better still as its own, or part of a plugin.

Save SEO titles and meta descriptions

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 a job

Associate another post with a 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.