Using JobRelay with Advanced Custom Fields (ACF)

If your job solution in WordPress (the way you are saving and presenting jobs) uses fields that are created with advanced custom fields, the code below will make this compatible.

By default, JobRelay uses the WordPress core function called update_post_meta() to save job data to a job post.

However, if you have setup your fields using ACF, you should really use the ACF function named update_field() to do this.

The code below corrects this issue. To use the code, copy this to a file and save in your WordPress wp-content/plugins folder. Navigate to the plugins page in your WordPress site and then activate the JobRelay ACF Compatibility Add-on plugin from the plugin listings.

<?php
/*
Plugin Name: JobRelay ACF Compatibility Add-on
Plugin URI: https://highrise.digital/
Description: Adds improvements to make JobRelay more compatible with ACF (Advanced Custom Fields).
Version: 1.0
License: GPL-2.0+
Author: Highrise Digital Ltd
Author URI: https://highrise.digital/
Text domain: jobrelay-connector-acf
*/

/* exist if directly accessed */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Saves the meta data for a job using ACF.
 *
 * @param integer $job_post_id The post ID of the newly created job.
 * @param string  $meta_key    The key of the field just saved.
 * @param string  $meta_calue  The value of the field just saved.
 * @param array   $job_data    The array of job data sent from JobRelay for this job.
 */
function jobrelay_save_acf_meta_data( $job_post_id, $meta_key, $meta_value, $job_data ) {

	// update the field using the acf function.
	if ( function_exists( 'update_field' ) ) {
		update_field( $meta_key, $meta_value, $job_post_id );
	}

}

add_action( 'jobrelay_wpcon_meta_added', 'jobrelay_save_acf_meta_data', 10, 4 );