Using JobRelay with the FacetWP plugin

Many users choose the excellent FacetWP plugin to provide a filterable show listing page. FacetWP has it own index which it uses when visitors to your site narrow down the job listings using Facets.

This index is usually updated when a job is saved or published in the WordPress admin, however as jobs from JobRelay are not written in the admin, this step can be missed.

The code below solves this problem, by updating the FacetWP index when a job is created using JobRelay. You could add this code to your themes functions.php or create a small plugin using the code.

<?php
/**
 * Re-indexes FacetWP when a new job arrives.
 *
 * @param integer $job_post_id     The newly created job post id.
 * @param array   $job_data        The array of job data sent from the multi poster.
 */
function hd_reset_job_facets( $job_post_id, $job_data ) {

	// if facetwp is active.
	if ( function_exists( 'FWP' ) ) {

		// run the indexer for the newly created job post.
		FWP()->indexer->index( absint( $job_post_id ) );

	}

}

add_action( 'jobrelay_wpcon_job_inserted_complete', 'hd_reset_job_facets', 30, 3 );