Job Expiration

In this article

JobRelay can only remove jobs from a WordPress site using the delete command sent by the provider, or when the provider removes a job from its feed, JobRelay will remove the job from the website.

Job expiration dates are also sent from some providers, but JobRelay itself does not expire jobs.

Broadbean, LogicMelon and Idibu

When your multi-posting service sends a job over to your website, they send with this an expiration date. This is sent in the date format of dd-mm-yyyy.

This expiration date will be saved in your WordPress site based on the field mappings you have set up. This is most likely to be setup to save as meta data against the newly created job post.

Even though the expiration date has been saved, it is up to your WordPress site to honour that expiration date, and expire the jobs on, or after that date.

How do I expire jobs on the expiration date?

This is a developer task and is usually achieved by creating a cron job. Essentially this is a function which runs at a specific time interval – whatever is appropriate for your site.

In WordPress cron jobs are registered, which a specific time interval and then you attach a function to the cron job to run when the job runs.

Here is an example that would check for expired jobs every 24 hours and remove jobs that are older than today.

/**
 * Registered our scheduler hook for expiring jobs.
 */
function hd_register_schedule() {

	// add our scheduled event.
	wp_schedule_event(
		time(), // when to start this event.
		'daily', // interval to run the schedule at.
		'hd_remove_expired_jobs' // name of the hook that fires when this event is fired.
	);

}

register_activation_hook( __FILE__, 'hd_register_schedule' );

/**
 * Removes the scheduled event when the plugin is deactivated.
 */
function hd_deregister_schedule() {

	// clear our scheduled event from wp
	wp_clear_scheduled_hook( 'hd_remove_expired_jobs' );

}

register_deactivation_hook( __FILE__, 'hd_deregister_schedule' );

/**
 * Removes jobs that have passed their expiry date.
 */
function hd_check_for_expired_jobs() {

	$job_ids = get_posts(
		[
			'post_type'      => 'job_listing', // change for the name of the jobs post type.
			'post_status'    => 'publish',
			'fields'         => 'ids',
			'posts_per_page' => 250,
			'meta_query'     => [
				'relation' => 'AND',
				[
					'key'     => '_job_expires', // change for the meta key storing the expiry date.
					'value'   => 0,
					'compare' => '>',
				],
				[
					'key'     => '_job_expires', // change for the meta key storing the expiry date
					'value'   => current_datetime(),
					'compare' => '<',
				],
			],
		]
	);

	if ( $job_ids ) {
		foreach ( $job_ids as $job_id ) {
			wp_trash_post( $job_id );
		}
	}

}

add_action( 'hd_remove_expired_jobs', 'hd_check_for_expired_jobs' );

This code needs to be added to your plugins root file.

JobAdder and Workable

JobAdder and Workable work a little different. With these providers, JobRelay pulls (or it is pushed to) your live list of jobs at a given interval. This is usually every 30 minutes, unless there are no changes made.

Any jobs found in that job feed are then processed and saved or updated in WordPress. Therefore to expire a job, it just needs removing from the live job feed provider by JobAdder or Workable.

Their support teams will be able to help with expiring a job and thus removing it from the job feed.